Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net MVC 4: Can we set Layout = null, when to Load Html Data from ajax Call?

I am adding another view page (with Ajax Request) into my existing view Page, like in this way -> $("divId").html(data); Here data is my View Page which I am getting with ajax call. My question is Can I remove 'Layout' or set it as Layout = Null, for this Ajax returned View page?

like image 508
himanshupareek66 Avatar asked Jul 31 '12 08:07

himanshupareek66


1 Answers

In controller action you can return a PartialView, this will only send the HTML from the view to the client without the code from the Layout. You may implement your Action this way:

public ActionResult MyAction()
{
    if (Request.IsAjaxRequest()) 
    {
         return PartialView();
    }
    return View();
}

So you can use the same Action for a normal and an Ajax request.

like image 142
DanielB Avatar answered Sep 30 '22 14:09

DanielB