---
title: "menu controls in mvc"  
description: "menu controls in mvc"  
author: "ravi kumar"  
published: 2011-11-01  
updated: 2011-11-01  
canonical: https://www.mindstick.com/forum/338/menu-controls-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# menu controls in mvc

Hi I am new to [mvc](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc). how to create a [dynamic](https://www.mindstick.com/blog/11080/features-of-java-dynamic-complied-and-interpreted) menu [controls](https://www.mindstick.com/articles/66/how-to-create-controls-at-run-time-in-csharp-dot-net) in mvc please help me

## Replies

### Reply by ravi kumar

Thank you Rohit

### Reply by Chris Anderson

Hi,\
\
You can dynamically create menu control in asp.net mvc by using ViewBag or ViewData properties.\
For eg:\
Create a action method (Index) in a controller as given below:\
\

```
public ActionResult Index()        {            List<string> hobby = new List<string>();            hobby.Add("Cricket");            hobby.Add("Football");            hobby.Add("Tennis");            ViewBag.Hobbies = hobby; //hobby is List            return View();        }
```

\
In an Index View use the below code:\
\

```
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %><html><head runat="server">    <title>Index</title>    <style type="text/css">        .required        {            text-decoration:none;        }        li        {            list-style-type:none;            display:inline;            margin-left:10px;        }    </style></head><body>    <div>        <ul>            <% foreach (var hobby in ViewBag.Hobbies) { %>            <li>                <font color="blue"><%: Html.ActionLink((string)hobby, "Index", "Home", new { @class = "required" })%></font>            </li>            <% } %>        </ul>    </div></body></html>
```


---

Original Source: https://www.mindstick.com/forum/338/menu-controls-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
