ArticleDirectory
- Renderpartial
- Renderaction
Master page (master) 1. The master page is not related to the controller. The master page is only a view file, and no controller corresponds to it. 2. In fact, the aspx of the view in ASP. net mvc is not closely associated with the master page as in webform. For example, if I want to change An ASPX master page, I only need to specify the master to be used when return is in the action: I have two master files, while/views/home/index. if you want to use Site2 as the master, you only need to specify the mastername parameter in return view of the action:
1: PublicActionresult index (){
2:ReturnView (Null,"Site2");
3:}
In the custom control renderpartialasp. Net MVC, if you want to use a custom control, you must use helper instead of using it like webform. For example, we create a CT. ascx with the following content:
1:<% @ Control Language ="C #"Inherits ="System. Web. MVC. viewusercontrol"%>
2:I'm CT. ascx.
Then, call it in index. aspx.
1:<% Html. renderpartial ("CT"); %>
OK (note that <% = %> is not used to display but execute the statement.) The final result is that the custom control can be placed in view/shared in addition to the caller's directory. In addition, this custom control is not supported by the Controller. It only extracts the view part for public use. What should we do if the ascx we want to call has logic processing or database calling, that is, when the controller is required. Renderactionok for example I want to have an ascx with independent logic. First I need to reference Microsoft. Web. MVC (http://aspnet.codeplex.com/Release/ProjectReleases.aspx? Releaseid = 24471) web. config/configuration/system. add <add namespace = "Microsoft. web. MVC "/> is the same action as creating an action:
1: PublicActionresult ctaction (){
2:ReturnPartialview ();// Note that this is not a view
3:}
View (ctaction. ascx)
1:<% @ Control Language ="C #"Inherits ="System. Web. MVC. viewusercontrol"%>
2:
3:Show current action: <% =This. Viewcontext. routedata. Values ["Action"] %>
View (index. aspx ):
1:<%
2:Html. renderaction ("Ctaction","Home"); %>
OK, and the result is: File Upload. The topic that has nothing to do with this article is File Upload. I will not explain it here,CodeIs the best language. View:
1:<Form action ="<% = URL. Action ("Process") %>"Enctype ="Multipart/form-Data"Method ="Post">
2:<Input name ="Up1"Type ="File"/> <Input type ="Submit"/>
3:</Form>
Action (process ):
1: PublicActionresult process (httppostedfilebase up1)
2:{// The parameter name must be the same as the name.
3:Up1.saveas (server. mappath ("~ /"+ Up1.filename ));
4:ReturnContent (up1.filename );
5:}
Show: After submitting: Check the folder again. The file has been uploaded successfully. This article was written for my big cousin because he is a tireless ASP instructor, I hope you can use the tutorials I have written. Thank you for your support.