0

how to use aspx menu functionality in ASP.NET MVC3. So that clicking on the menu item will poplulate the gridview.

2
  • +1 Well I think it is a great question, considering that it's called ASP.NET MVC and yet does not allow ASP tags... the name itself seems to be misleading. Commented Sep 14, 2013 at 2:46
  • And conceptually, the web-forms asp:Menu simplified 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). Commented Sep 14, 2013 at 2:48

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the clarification @Shyju. So why is ASP.NET MVC still prefaced with "ASP.NET" when it does not allow the usage of asp: tags?
@IanCampbell: Because it uses the ASP.NET framework like webforms do
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.