Skip to content
Advertisement

C# load cshtml into modal with JQuery

I want to load the content from one page into a modal on another page on the click of a button, but it is also loading in the content from the __Layout page. I have tried calling a controller using:

$('.btn').click(function(){
    $('.container').load('/Home/MyPage');
})


<div class="container"></div>

However, I cannot get it to load in solely what is in the MyPage.cshtml file. What am I doing wrong? Any help would be great, thanks.

Advertisement

Answer

Add the below snippet on top of MyPage.cshtml to avoid loading with the layout page.

@{
    Layout = null;
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement