MVC branch view and mvc branch view

Source: Internet
Author: User

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 ();}

 

Related Article

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.