how to use aspx menu functionality in ASP.NET MVC3. So that clicking on the menu item will poplulate the gridview.
2 Answers
ASP.NET MVC Does not have any Server controls like what we have in ASP.NET WebForms. It is all about writing pure HTML code by hand. ( All the server controls in Webforms also generates HTML and render to browser)
What you can do is, Have a tags for your menu item. Then on click, you can call another action method which loads all the data you want to show in the tabular format. If these menus are going to be in all pages, you can keep them inside the _layout.cshtml which will act like a Master page.
IF you want to load some data to the Table(UI) without a page reload, you can do it with jQuery ajax.
Assuming you have some markuplike this for your Menu, The below code loads response from your Action methods using the jQuery load function.
//Don't forget to include jQuery library
<ul>
<li>@Html.ActionLink("Users","List","Users",null,new {@class="ajaXMenu"})</li>
<li>@Html.ActionLink("Jobs","List","Jobs",null,new {@class="ajaXMenu"})</li>
</ul>
<div id="contentDiv"></div>
<script type="text/javascript>
$(function(){
$("a.ajaXMenu").click(function(e){
e.preventDefault();
$("#contentDiv").load($(this).attr("href"));
});
});
</script>
2 Comments
ASP.NET MVC still prefaced with "ASP.NET" when it does not allow the usage of asp: tags?first you'll probably want to look into something like sitemaps for MVC, which there is a really good open source option: https://github.com/maartenba/MvcSiteMapProvider
Then you'll want the actual menu. There is no MVC menu control, so you'll have to either create one yourself, or use someone else's. Twitter bootstrap has a nav menu that is fairly good: http://twitter.github.com/bootstrap/components.html#navbar
Additionally, telerik has a menu that you can use as well, but this one you need a license for: http://demos.kendoui.com/web/menu/index.html
ASP.NET MVCand yet does not allowASPtags... the name itself seems to be misleading.asp:Menusimplified the CSS rendering of an<ul>you have to do with just raw HTML (it would be nice to still have a similar functionality with MVC).