In ASP. NET mvc3, request. isajaxrequest () is used to determine whether to load public views.

Source: Internet
Author: User

ASP. in net mvc3, we can go to "_ viewstart. in cshtml, specify layout as the "_ layout. cshtml "Page, of course, we can also go to" _ viewstart. in cshtml, different la s are loaded as needed. _ Viewstart. cshtml I have defined a public view, including the page header and the end of the page.

What I want to solve is that when jquery is used for Ajax requests, public views do not need to be loaded.

 
<SCRIPT type = "text/JavaScript">
$ (Function(){
$ ('# Thelink'). Click (Function(){
$. Ajax ({
URL: $ (This). ATTR ('href '),
Type: "Get ",
Success:Function(Response ){
Response ('{maincontent'{.html (response );
}
});
Return False;
});
});
</SCRIPT>

The method is as follows:

In ~ /Views/viewstart. cshtml

 
@{
Layout = request. isajaxrequest ()?Null:"~ /Views/shared/_ layout. cshtml";
}
 

In controller:

PublicActionresult index ()
{
ReturnView ();
}

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.