html - Render partial view upon menu selection -



html - Render partial view upon menu selection -

i've got tab menu want utilize show different partial views depending on menu item selection. how looks like:

something like: if selected item 1, render view "whatever"...

i want click on 1st menu item , render partial view tab1, 2nd menu item , render partial view tab2, etc...

edit - have been trying

the view:

<div class="tabs"> <ul> <li><a class="tab" id="tab1" href="#">personal data</a></li> <li><a class="tab" id="tab2" href="#">user image</a></li> <li><a class="tab" id="tab3" href="#">regional definitions</a></li> <li><a class="tab" id="tab4" href="#">colors , themes</a></li> <li><a class="tab" id="tab5" href='#'>personal area</a></li> </ul> </div> <div id="div-for-partial"> </div> ... <script type="text/javascript"> $(function () { $('.tab').click(function () { var id = this.id; $.ajax({ type: 'post', url: '@url.action("getpartialview", "configcontroller")', data: { 'id': id }, datatype: "html", success: function (data) { $('#div-for-partial').html(data); } }); }); }); </script>

the controller:

public actionresult index() { homecoming view(); } [httppost] public actionresult getpartialview(string id) { switch (id) { case "tab1": homecoming partialview("_personaldata"); case "tab2": homecoming partialview("_userimage"); } homecoming redirecttoaction("index"); }

implementing ajax not complicated. first assign each of tabs unique id , mutual class.

<div class="tabs"> <ul> <li><a href="#" class="tab" id="tab1">tab 1</a></li> <li><a href="#" class="tab" id="tab2>tab 2</a></li> <li><a href="#" class="tab" id="tab3>tab 3</a></li> </ul> </div>

then, create controller action post to.

public actionresult getpartialview(string id) { switch(id) { case "tab1": homecoming partialview("_partialfortab1"); case "tab2": homecoming partialview("_partialfortab2"); case "tab3": homecoming partialview("_partialfortab3"); } homecoming redirecttoaction("yourhomepage"); }

add click event handler tabs:

<script type="text/javascript"> $(function () { $('.tab').click(function() { var id = this.id; $.get('@url.content("getpartialview")', { 'id': id }, function (data) { $('#div-for-partial').html(data); }); }); }); </script>

html asp.net-mvc razor

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -