The ingenious use of the MVC partial view

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.