The clever use of some MVC views

Source: Internet
Author: User

The clever use of some MVC views

View Interface

 @{ Html.RenderAction("demo", "", new { id = ViewBag.id });}

Request Controller Method

 public ActionResult Index(int? id)        {             ViewBag.id = id;            return View();        }        

Partial View Method

// Here it will find the view, the name must be the same, if not, specify public PartialViewResult demo (string id) below) {// some operations on the database ///| //··········//··········//······ ····//··········//··········//·········· return PartialView (); // return some views, that is, the data content section to be displayed on the main view}

  

This allows multiple interfaces to be shared, for example:

1. Click "category" to display related product data

2. Click the brand to display the relevant product data

3. Search for products and display data

4 ,············

 

Step 1: Check the front-end interface and data usage

Step 2: copy the html code of the Data queried from the database and the relevant operation code to some view pages (some views are empty and copy the part to be displayed directly, different situations may require introduction of namespace @ using xxx)

Step 3: Master view method receiving

ViewBag. id = id;

// Jump to the view
Return View ();

// In the blank area of the view page, that is, the html code that is taken to display data is put in
@ {Html. RenderAction ("demo", "", new {id = ViewBag. id });}

Step 4: Create methods with the same name in the controller. The names must be the same. If they are different, specify them in the method body.


Success ....


If you have time to introduce TempData... it is more suitable for different parameter types.

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.