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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With