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.