简体   繁体   中英

C# MVC4 Razor Partial Views - Full page refreshing while switching views?

Am building a typical admin portal - there's two shared partial view .cshtml files for top and left menus. Then, the main content is the usual view files.

Example, I have in "views" a "dashboard.cshtml" and "settings.cshtml" and so on. Inside these, I make a call to @Html.Partial("_Layout_topmenu") and @Html.Partial("_Layout.leftnav")

Everything is "working" fine, except that when I click around from "dashboard" to "settings" and back to "dashboard", I see the entire screen refresh. I was expecting only the main content portion to refresh while the top and left navs would stay the same since they are partial views.. am I missing something?

In the controller code for the "Dashboard" and "Settings" GET methods that return the ActionResult type, I am simply returning view();

So is it possible to hold on to the top menu and left nav panes and keep changing the main content while moving from //site/controller/view1 to //site/controller/view2 (and without involving jQuery/AJAX magic)... ?

Thanks!

unless you're using frames, which i don't think you are, or you are manually loading the partial views' html via ajax into their respective containers, you're just making a regular http request. the partial views are only on the server, not client side, so when you make a request for a given page, the whole thing is reloaded.

if you want to load the content area independently of the other areas, i would suggest looking into returning PartialView() from your controller method, and calling that method via jQuery's .load() method.


EDIT

without using jquery/other magic, no. if you make a request for a page, you're going to load a page. this should not be a suprise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM