Asp.net mvc tour-the second station snoops various results under the Controller, mvccontroller
When encoding in actions, we all know that all types of return values of actions are ActionResult, and our return values are also a variety of wonders, such as Json (), Content (),
View () and so on... When you write this code, do you have a strong desire to gain a peek... Let's take a look at this article.
I. instance code
1 public class HomeController : Controller 2 { 3 public ActionResult Index() 4 { 5 ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; 6 7 return View(); 8 } 9 10 public ActionResult About()11 {12 ViewBag.Message = "Your app description page.";13 14 return Json("");15 }16 17 public ActionResult Contact()18 {19 ViewBag.Message = "Your contact page.";20 21 return Content("");22 }23 }
1. View ()
Still the old rule. Let's use ILSpy to see what the source code will look like...
As shown in the preceding figure, we can see that when we perform View () in Action, we only perform a new ViewResult operation internally, and then the code continues
The ViewEngineCollection collection is used to find the View I need. Some people have doubts about how to fill the ViewEngineCollection. In fact, I don't know how to fill it...
However, we can see that if a View can be found in the Collection, a viewEngineResult will be returned. If no View is found, the path will be searched through SearchedLocations.
Print all paths... As shown below, Is it interesting?
2. Json ()
In the context of the rich client, there are almost no programs that do not use Json (). We usually only need to plug the Model into Json, and the client is already a Json string, yes
There is no doubt. Next we will continue to look at how to play in its source code...
From the code above, we can see that the so-called Json is actually nothing... It's just response. write (xxxx. serialize (xxxx). I thought it was something tall...
Actually ??? You know...
3. Content ()
After you understand Json (), I think you should be clear about the principle of Content, because Json still needs to use the javascriptSerializer serializer to serialize the Model.
The serialized json is actually sent to the client. You can guess that Content will not do this at all, but simply spray the string to the front-end... Right...
Okay, it's late at night... Here is a simple analysis. The other results are under the Controller class. If you are willing to use ILSpy to view the results, everything is not a question.
For example, in the following example, a simple Controller has five results...