View View interface
@{html.renderaction ("demo", "", new {id = viewbag.id});}
The requested Controller method
Public ActionResult Index (int? id) { viewbag.id = ID; return View (); }
Partial View methods
Here it will find the view, the name must be the same, if not the same, specify the public Partialviewresult demo (string id) { //Some operations on the database // //·········· //·········· //·········· //·········· //·········· return Partialview ();//Returns the partial view, which is the data Content section to be displayed on the main page }
This approach allows multiple interfaces to be shared, such as:
1. Click the category to display the relevant product data
2, click on the brand display related product data
3, search products, display data
4,
First step: Confirm the front-end interface, and the part of the data used
The second step: Copy the data HTML code that contains the query from the database and the related presentation operation code to the partial view page (some of the views are empty, the piece that is going to be shown directly is copied in, it may be necessary to introduce a namespace @using xxx)
Step three: The main view method receives
Viewbag.id = ID;
Jump to view
return View ();
In the empty area of the view page, which is the HTML code that was taken to display the data, put
@{html.renderaction ("demo", "", new {id = viewbag.id});}
Fourth step: In the controller to create the same name method, the name must be the same, if not the same, in the method body inside the specified
Done....
Have time to introduce tempdata ..... Suitable for different types of required parameters
The ingenious use of the MVC partial view