If I have a 2 pages both using the same layout page, is there a way I can navigate between the 2 pages and only refresh the body part of the layout page. For example if I have a list page and select an item to go to the detail page and they both contain
the same layout view, I don't want the layout which contains the menu to reload, just the page containing the layout view similar to a partial page postback. Thanks.
Thanks for the response. I'm using MVC 3, so I guess I would need to go the manual Jquery route. I'm a little confused on how to do this using a layout. Are you suggesting not using a layout and have the layout be the view and return each page as a partial
view within a page, or is there some other way to do this. Each view in my application is using a layout like below. Can you give me an example of how to do this with jquery?
@{
ViewBag.Title ="My
List Page"; Layout ="~/Views/Shared/_MainUserMenu.cshtml"; }
No you would still use a layout, but wrap the views in a div tag on the layout page. Then write a little big of jquery to intercept any links and instead of redirecting the page there, load the page via an ajax request and put the results into the div replacing
it's content.
atllocal74
Member
19 Points
38 Posts
How to avoid refresh of layout view when navigating between pages
Mar 27, 2012 09:35 PM|LINK
If I have a 2 pages both using the same layout page, is there a way I can navigate between the 2 pages and only refresh the body part of the layout page. For example if I have a list page and select an item to go to the detail page and they both contain the same layout view, I don't want the layout which contains the menu to reload, just the page containing the layout view similar to a partial page postback. Thanks.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: How to avoid refresh of layout view when navigating between pages
Mar 27, 2012 09:43 PM|LINK
You can do that using javascript and ajax. You can either do it manually using JQuery or look into the new MVC 4 single page application template.
http://www.asp.net/single-page-application
Blog | Twitter : @Hattan
atllocal74
Member
19 Points
38 Posts
Re: How to avoid refresh of layout view when navigating between pages
Mar 27, 2012 10:08 PM|LINK
Thanks for the response. I'm using MVC 3, so I guess I would need to go the manual Jquery route. I'm a little confused on how to do this using a layout. Are you suggesting not using a layout and have the layout be the view and return each page as a partial view within a page, or is there some other way to do this. Each view in my application is using a layout like below. Can you give me an example of how to do this with jquery?
@{
ViewBag.Title ="My List Page";
Layout ="~/Views/Shared/_MainUserMenu.cshtml";
}
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: How to avoid refresh of layout view when navigating between pages
Mar 27, 2012 10:15 PM|LINK
The layout remains . Just add DOM elements.
Please see http://bit.ly/mvc_ajax_jquery
CodeHobo
All-Star
18647 Points
2647 Posts
Re: How to avoid refresh of layout view when navigating between pages
Mar 27, 2012 10:17 PM|LINK
No you would still use a layout, but wrap the views in a div tag on the layout page. Then write a little big of jquery to intercept any links and instead of redirecting the page there, load the page via an ajax request and put the results into the div replacing it's content.
Blog | Twitter : @Hattan