I am working on a project and in order to not have the Layout view being reloaded with every page change, I decided to change my views to partial views. In order to load the views when a user clicks on one of the menu items in the navigation menu I am now using jquery ajax like the following:-
$("ul.metismenu a:not(.subMenuParent)").unbind().click(function (e) {
e.preventDefault();
var url = $(this).attr("href");
window.history.pushState("", "", url);
$.ajax({
url: url,
dataType: 'html',
success: function (data) {
$('#page-content').html(data);
}
});
});
The element page-content resides in the Layout view. It is working fine, however the issue I am encountering now is that when i try to access the View directly say i go /Dashboard directly in the browser I will get just the partial view, without the Layout page. Anyone got some ideas how I can solve this please? Thank you in advance for any advice.
@{ Layout = "~/Views/Shared/_Layout.cshtml" }in your partial view.