In WebForm we have used the user control to reduce duplication of code and also facilitate the page modularity,
In MVC, a partial view, partial view. , is a view of a fragment. You can use partial view to wrap this part of the HTML or display logic to facilitate repeated references, when the created partial view is placed in the views/shared directory, The action or view under any controller can be loaded, and the shared partial view is placed under a shared file. How to build? As with the steps to create a view, just choose Add---view to tick on the "Create as Partial View" (as long as tick on, the established view page will not have any preset content, then we try to display the partial view page with HTML snippet) Note: Using a distributed view does not necessarily require a related action, because it is only the HTML of the fragment and is not invoked when the action is executed. How to load? The HTML helper method has a dedicated enrichment method to load the partial view, which can be used to retrieve the execution results of the partial view directly in view. Partial (htmlhelper,string) Partial (Htmlhelper,string,object) Partial (htmlhelper,string,viewdatadictionary) Partial (htmlhelper,string,object,viewdatadictionary)-----html.partial ("Ajaxpage") html.partial ("AjaxPage", Model ) html.partial ("Ajaxpage", null,viewdata["model"]) html.partial ("Ajaxpage", model,null,viewdata["model"]) loading a partial view from a controller partial view in addition to being able to load directly from the view page, you can also use from the controller like a view page, such as Return Partialview () The only difference between this approach and the view helper method is that it does not apply to the main page. loading a partial view using the Html.action helper method in addition to using partial loading of partial views on the View page, you can also enable in MVC The execution result of another action is loaded with the Html.action helper method. Eg:public ActionResult aaa () {return Partialview ();} You can then use html.action to load the execution results @Html of this action on the View page. Action ("AAA") difference: @Html. Partial load partial view is read directly through HtmlHelper *. cshtml pieces, directly perform the view and get results, if you use Html.action, then HtmlHelper to the IIS again processing requirements (through Server.Execute method ), Therefore, Html.action will re-execute the controller's life cycle again. @Html. displaynamefor (model = model. e-mail) only output simple text, completely no additional tags, and the output of the display text is in the member data model in the field displayname attribute (Attributes) parameters values, If you do not define a parameter value for the DisplayName property, the preset will output the property name. @Html. displayfor (model = model. e-mail) is a template-assisted method, specifically used to output the display template, found that most of the fields are straight output data model incoming values (no additional HTML tags), but there is a special field is not the same, that is, email this field output, because the output of this field is a hyperlink-containing email address. Custom HTML helper methods.
Loading partial views using HTML helper methods