Asp. Net MVC3.0 Partial RenderPartial Action RenderAction differences and usage,
I do not write many blog posts and have poor professional knowledge. The following are my personal notes. If there is any problem, please take different approaches and provide brick-and-mortar guidance. Thank you!
Differences:
1. The properties of Partial and RenderPartial are basically the same, but a static user control is embedded in.
2. Partial returns a bunch of html code and writes it directly to the page @ Html. Partial ("ViewName ");
3. RenderPartial Void is returned, and this method will add the specified View @ {Html. RenderPartial ("ViewName");} on the home page ");}
4. The properties of Partial and RenderPartial methods are basically the same, but the Controller is not used to embed a static user control.
5. The RenderAction and Action are a little different. The Controller will be used to return a page.
6. The data of RenderPatial and Partial comes from the called View page. RenderAction and Action initiate a new Request to the Controller, but RenderPatial does not.
Usage:
Method referenced by different Controllers
@ Html. Partial ("~ /Views/Ascx/Head. cshtml ") // user control path
@ {Html. RenderPartial ("~ /Views/Ascx/Head. cshtml ");}
@ Html. Action ("Head", "Ascx") // Ascx controller name, Head user control name
@ {Html. RenderAction ("Head", "Ascx ");}
Same controller reference method
@ Html. Partial ("Head") // Head user control name
@ {Html. RenderPartial ("Head ");}
@ Html. Action ("Head") <br/> // Head Method Name
@ {Html. RenderAction ("Head ");}
Both RenderPartial and RenderAction must be written in.
Public ActionResult Head ()
{
ViewBag. Test = "(Home) call ";
Return PartialView ();
}