Visual Studio 2015: MVC 6 Scaffolding switched to using IActionResult with ActionResult

I just installed VS 2015, and I noticed a few changes in auto-scaffolding MVC6. I'm curious why Microsoft made these changes because I think that if they decide to do some, there may be some advantages that I may not know about.

VS 2013 always uses Auto-Scaffolding MVC 5: ActionResult

In VS 2015 MVC 6 Auto-Scaffolding switched to using: IActionResult

In VS 2015, I notice that the Microsoft team prefers not to do this anymore:

public class Test{ private int i; public Test (int i){ this.i = i; } } 

So far in all the generated classes, I saw what they did:

  public class Test{ private int _i; public Test (int i){ _i = i; } } 

If it is only about the coding style, then I will immediately lose my interests in the well-known why they changed it, but if there is any logical explanation, I can not wait to find out what it is.

+5
source share
1 answer

Regarding the ActionResult question, in previous ASP.NET, MVCs used the Parent System.Web.MVC.Controller class, and the Web APIs used the Parent System.Web.Http.ApiController class.

But in ASP.NET 5 MVC 6 they are combined as in a single web application. So, now there is only one class of the Microsoft.AspNet.Mvc.Controller class as a base for them. Now, to distinguish them from them, when used as an MVC controller, IActionResult can be a view. When used as a controller web API, IActionResult can be data (JSON / XML). The same controller can have actions that return both views and data.

+3
source

All Articles