2
I need to change the URL of the page according to the Partialview that I load via Ajax.
@EDIT
In addition, I also need to free direct access to Partialview via URL, but, bringing with you the page "father" because I work with it so that it performs functions of Masterpage, ie, I load in it scripts and layout. I wanted to avoid importing in each page my scripts.
Solved by adding $('#footer'). load('/Web/Footer'); to render a Partialview as footer
I have the following code in my View
<div class="conteudo">
<!-- Conteudo regular do site -->
</div>
<div id="corpoConteudo"></div>
via Ajax, I carry the content of PartialView
within the <div id="corpoConteudo">
My script is this
function Open(url) {
Carregar();
url = '@Url.Content("~/")' + url;
$.ajax({
url: url,
type: 'GET',
success: function (response) {
$('#corpoConteudo').html(response);
$('#loader').remove();
},
error: function () {
alert('Ocorreu um erro!');
$('#loader').remove();
}
});
}
function Carregar() {
$('#corpoConteudo').append('<div id="loader"></div>');
}
"To bring with you the parent page, "in my view, is to call the parent page. In MVC is not called the child content to bring the parent content, but the opposite. That’s precisely why Razor doesn’t have the concept of
MasterPage
, and yes, the concept of Layout. What pages do you need to call? Could you please improve your response?– Leonel Sanches da Silva
Basically my Index page is treated as a Masterpage, because in it I give the header, Nav and footer. In the middle of it, in the div id="corpoConteudo", I bring my Partialview. For example: Case, News and so on. Accessing: http://localhost:3245/ I go straight to Index and then clicking on an element, navigate to Partialview. If access: http://localhost:3245/Web/Case, being my Web Controller and Case to Partialview, I do not load the elements (Header, Nav, Footer) because they are in my Index. I would like to do this against hand and also update the URL with Partialview that I carry.
– Rafael Barbosa
So in my view this is an approach problem. The right one would be the
Ajax
carry anotherAction
(that brings only the Partial), and theActions
use standardViews
Father to load the Layout in full.– Leonel Sanches da Silva
I understand and I agree with you. Furthermore, I edited my question with the solution I found to treat the problem the way the project is.
– Rafael Barbosa
@Ciganomorrisonmendez, replacing the Partials with Views, it is no longer necessary to use a Partial that only loads the footer, because the footer will already be contained in the Layout. Using a Layout, for every Action call, will load the full page, so it is not causing items that have already been loaded to reload?
– Diego Zanardo
@Diegozanardo And what’s the problem in that? If I make a non-ajax request, I have to return the whole page anyway.
– Leonel Sanches da Silva