0
I am developing a site in ASP.NET MVC, I wanted that when I changed screen only be updated my div .ESTRUTURA here is the code:
Javascript:
function loadPage(page) {
$.ajax({
type: 'GET',
url: page,
dataType: 'html',
cache: true,
async: true,
success: function (data) {
console.log($('.ESTRUTURA').html(data));
$('.ESTRUTURA').html(data);
}
});
}
HTML (In this case it is the _Layout.cshtml)
<body>
<div class="bg">
@Html.Partial("_Header")
<div class="ESTRUTURA">
@RenderBody()
</div>
@Html.Partial("_Footer")
</div>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/vendors/underscore.js"></script>
<script src="~/Scripts/vendors/backbone.js"></script>
<script src="~/Scripts/app.js"></script>
</body>
Inside my DIV .ESTRUTURA has the @RenderBody(), I believe the problem is there. The variable data, receives the entire HTML of the page (but should not).
So your problem is in the construction of the variable
data. You must review what you are getting in your request ajax– CesarMiguel
The variable receives the return of @Renderbody(), I was able to fix this problem by changing the return of the controllers to Partialview(), but the first page I load (Home), has to be View(), otherwise the other content of the page like Header Footer and navbar
– Danilo Oliveira
That’s right, your home has to be a view. However I see your problem... The variable
datareceive the return of the Renderbody??– CesarMiguel
Yes, that in the case when I put Partialview(), the Renderbody() only and returns content, but when I put View() it returns me the whole page, I need him to only run the Home View() the first time, the others need to be like Partialview()
– Danilo Oliveira