ASP.net MVC and asp. netmvc

Source: Internet
Author: User

ASP.net MVC and asp. netmvc

After a brief understanding of the basic development steps of MVC, I have a detailed look at the MVC syntax and templates.

For mvc development, we must first have a basic understanding of the layout. Razor engine makes page elements clearer

Simple understanding

 

  • Allows you to load css, js, and other files for unified management and settings.

     

    For example

     

     
    1234 <linkhref="@url.content("~ content="" site.css")"rel="stylesheet" type="text/css"><scriptsrc="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"type="text/javascript"></script><scriptsrc="@Url.Content("~/Scripts/jquery-1.7.js")"type="text/javascript"></script><scriptsrc="@Url.Content("../../Scripts/Highcharts-3.0.1/js/highcharts.js")"type="text/javascript"></script></linkhref="@url.content("~>

     

    The corresponding js is automatically found on the page.

     

    On the template page, we will define some global CSS, JS, and other files. The CSS and JS files and Code related to the specific page can be retained in @ RenderSection ("Head ", false), which allows the page to present personalized code in the form of @ section Head {}. The parameter "false" indicates that the specific page does not implement this section Head block.

    Template page definition

     

     
    123       <div class="page">  @RenderSection("Head", false); <! -- The page may contain no Head nodes --></div><span style="font-family: SimSun;font-size:18px; "> </span>

     

    Add About. cshtml,

    Then you can define the content to be presented by "Head" in About. cshtml.

     

     
    12345 @section Head{  <script>       alert("Hello MVC3");    </script> }

     

    • Division View

     

    It can be a system plug-in, that is, something that can be separated should never be put together, because only each functional module is independent, we can reuse the division of labor and cooperation in other places. Now is an era of cooperation. No one can complete the prescribed tasks without cooperating with others, unless it is a good person. The Division view can bring us the division of labor and cooperation in different development modules. Html. partial and RenderPartial

    Html. both partial and RenderPartial output html fragments. The difference is that Partial directly generates a string and returns the View content (equivalent to an escape process ), the RenderPartial method is to directly output the data to the current HttpContext (because the data is directly output, the performance is good ). Therefore, they are used differently in the view.

    Comparative Analysis

    @ Html. Partial, @ Html. Action, @ Html. RenderPartial, @ Html. RenderAction, @ Html. ActionLink

    The preceding Methods call and return information.

    Differences

    1. the return value of the Render method is void, which is output within the method. The return value type without the Render is MvcHtmlString. Therefore, you can only use the following method:

     

     
    12 @Html. Partial corresponds to @ {Html. RenderPartial (....);}@Html. Action corresponds to @ {Html. RenderAction (....);}

     

    2. Html. Partial can directly provide the user control name as a parameter,

    The Html. Action must have the corresponding Action. In the Action, the PartailResult (retunPartialView () is returned ()).

    3. Html. Partial is recommended for simple user controls without any logic. Html. Action is recommended for user controls that require some Model settings. Of course, the Html. Partial method can also be used for Model data. You can refer to the method overload.

    Control knowledge

    Control is an abstract class that encapsulates many methods. Many return types are reference types. Therefore, when writing the return value, we try to view the parent class method as much as possible.

    For example, if we find the virtual method of the parent class, we can return the following types through control.

     

    FileContentResultfile () ContentResultcontent () JesonResultjson () PartialViewResultpartialView () ReirectToresultResultRediretToaction ()

     

    Summary:

    The writing and syntax after MVC3 are much easier to develop. At the same time, some distributed views are added to achieve good development results. The learning difficulty has not increased. This summary is a simple understanding of learning. Please give me more advice.

 

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.