ASP. NET MVC Tour--second stop spy on the various result under controller

Source: Internet
Author: User

When we encode in action, we all know that all the action return value types are ActionResult, and our return value is also a variety of wonderful things, such as Json (), Content (),

View (), etc... When you write this code, do you have a strong sense of peeping ... Let's have a look at this one.

One: Instance code

1      Public classHomecontroller:controller2     {3          Publicactionresult Index ()4         {5Viewbag.message ="Modify This template to jump-start your ASP application.";6 7             returnView ();8         }9 Ten          PublicActionResult About () One         { AViewbag.message ="Your App description page."; -  -             returnJson (""); the         } -  -          Publicactionresult Contact () -         { +Viewbag.message ="Your Contact page."; -  +             returnContent (""); A         } at}

1. View ()

Or the usual, we use Ilspy to see how its source code will be ...

From the above figure, we can probably see that, in fact, when we do view () in action, the inside is only doing a new viewresult operation, and then the code will continue from

Viewenginecollection this collection to find the view I need, then someone doubts, viewenginecollection this collection how to fill, in fact, I do not know ...

But we can see that if we can find the view in the collection, we will return a viewengineresult back, if not found, then through Searchedlocations will find the way

The path is all printed out ... Just like the following, isn't it interesting?

2.Json ()

In the context of the current rich client, almost no program does not JSON (), we usually have to plug the model to JSON, the client is already a JSON string, this is definitely

There is no doubt, the following we also continue to see its source code inside exactly how to play ...

As you can see from the code above, there is nothing in the so-called JSON ... Just Response.Write (Xxxx.serialize (xxxx)), this thought is what tall on the thing ...

In fact, what??? You know...

3. Content ()

After you know the JSON (), I think you should be very clear about how the content works, because JSON still needs to serialize the model with the JavaScriptSerializer serializer before

is really to send the serialized JSON to the client, you also guessed that the content will not do so, but just to spray string to the front ... Right...

Well, it's late. The simple analysis here, the other several results are under the Controller class, if you are willing to use Ilspy to see, then everything is not asked

Problem, such as the following I in the controller in a simple there are 5 result ...

ASP. NET MVC Tour--second stop spy on the various result under controller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.