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> } |
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 RenderPartialHtml. 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 knowledgeControl 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.