MVC branch view and mvc branch view
1. Request the branch view above the View:
First create a new controller, and then create a view without the default Index method. In this view, request the branch view
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. mvc; namespace MVCStatrApp. controllers {public class PartController: Controller {// GET: Part public ActionResult Index () {return View ();} /// <summary> /// division view method /// </summary> /// <returns> </returns> public ActionResult _ PartialTest () {return View ();}}}
In the Index of the List page:
@ {ViewBag. title = "Index" ;}@ section scripts {<script type = "text/javascript"> window. onload = function () {// obtain the button and add a click method document for it. getElementById ("btnLoadPart "). onclick = function () {// 1. create an asynchronous object XMLHttpRequest var xhr = new XMLHttpRequest (); // 2. call the open method xhr of the XMLHttpRequest object. open ("get", "/Part/_ PartialTest", true); // because it is a get asynchronous request, in order not to use the cache, use this sentence // The second parameter to randomly assign a value to xhr. setRequestHeader ("If-Modifie D-Since ", 0) // 3. Set the event of the XMLHttprequest object and add the callback function xhr. onreadystatechange = function () {if (xhr. readyState = 4 & xhr. status = 200) {// retrieve the data var xhrNew = xhr. responseText; // obtain the play data and place it in the DIV document. getElementById ("div1 "). innerHTML = xhrNew ;}}; // send xhr. send (null );};}; </script >}< h2> Index
Segment view page:
<Table> <tr> <td> Name: </td> <input type = "text" name = "txtName"/> </td> </tr> <td> password: </td> <input type = "text" name = "txtPwd"/> </td> </tr> </table>
On the _ ViewStart page, add a line of code:
@ {Layout = "~ /Views/Shared/_ Layout. cshtml ";} wow, Haha, I am the content of the ViewStart page.
When you click the button on the Index page:
It can be seen that when requesting the segment view, we also searched for the _ ViewStart page. How can we not load the _ ViewStart page?
You can modify the return method of the branch view:
/// <Summary> /// division view method /// </summary> /// <returns> </returns> public ActionResult _ PartialTest () {return PartialView ();}