简体   繁体   中英

ASP.NET MVC loading multiple partial views into a single div using JQuery

I am working on a help page which is composed of a navigation tree, content box, and search box. The navigation tree has links to Frequently Asked Questions and Glossary, each of which are linked to an Action which return partial views.

To the right of the navigation tree I have a single content div that I would like to contain whichever partial view is selected in the navigation tree.

clicking on one of the FAQ links calls the FAQ() method in my controller, then returns a partial view which is then displayed in my content div to the right of the navigation tree. 单击FAQ链接之一将在控制器中调用FAQ()方法,然后返回部分视图,该视图随后显示在导航树右侧的内容div中。 Clicking on another item would cause another partial view to be loaded.

How do I go about this? I've read a ton of ASP.NET MVC JQuery loading blog posts and tutorials but can't find anyone who's done exactly this.

Many thanks!

You should be able to use the jQuery method .load() to load HTML into your div. http://api.jquery.com/load/

You can create an action that returns the partial view as HTML. ASP.NET MVC Returning Partial View as a full View Page

jQuery: one easy way you can do is load all partial views in "Container Div" at page load in one go (if performance is not a issue) then assign each partial div with different div id inside "container", than use jquery to control show(); hide(); for each div.

MVC: however if i were you, "Glossary" and "FAQ" looks same model to me it shouldn't be put in different partial view in first place. if they did designed in separate model, in this scenario, i would recommend you to create a proxy class as a ViewModel above models you want to display, and then load it with one partial view only

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