asp.net mvc 4 - RAZOR Syntax building a menu -


i dipping in mvc4 , razor first time: trying build menu dynamically:

 @foreach (var menu in model.menu)  { <li>  html.actionlink("@menu.name", "@menu.view", "@menu.controller"); </li> } 

the menu class works output not literal, rather string:

html.actionlink("home", "index", "home"); html.actionlink("menu1", "index", "menu1"); html.actionlink("menu2", "index", "menu2");

what need change output actual literals?

edit: used basis above:

<li>@html.actionlink("menu1", "index", "menu1")</li> 

menu class:

 public class menuitem     {         public string name { get; set; }         public bool isactive { get; set; }         public string controller { get; set; }         public string view { get; set; }     } 

try this, have not set @ before html.actionlink treating text

@foreach (var menu in model.menu) {     <li>         @html.actionlink((string)menu.name, (string)menu.view, (string)menu.controller)     </li> } 

edit: cast string or can try

@linkextensions.actionlink(html, menu.name, menu.view, menu.controller) 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -