-1

I want to have a dynamic value.

I got this code but it does not work. it shows length in url instead of parameter i've given:

@model IEnumerable<WebInboxTool.Models.MenuItem>

<div>
@foreach (var item in Model)
{
  @Html.ActionLink(item.Name, item.ActionName, item.ControllerName,item.Parameters, null);
}
</div> 

MenuItem:

    public class MenuItem
{
    public string Name { get; set; }
    public string ActionName { get; set; }
    public string  ControllerName{ get; set; }
    public object Parameters { get; set; }

}

}

Layout Page where it will get rendered:

<div id="menu" class="menu">
    <div class="menu-head">
        <h2>Inbox Tool</h2>
    </div>

    @{ Html.RenderAction("MailboxMenu", "PartialMenu"); }
</div>
Amsel
  • 107
  • 1
  • 13
  • If the value of `Parameters` is an `object` - say `Parameters = new { someName = someValue }` then you code works perfectly fine. Your obviously setting it to a `string` as in `Parameters = "xxx"` which would create `length="3"` (when you ask a question, show the relevant code so it can be reproduced) –  Mar 22 '17 at 22:41

1 Answers1

2

Seems your action link is wrong.

@Html.ActionLink("Link text", "action", "controller", new { id = something }, null)

In your case, you can do something like this.

<div>
@foreach (var item in Model)
{
 @Html.ActionLink(item.Name, item.ActionName, item.ControllerName, new { id = item.Parameters }, null);
}
</div> 
Jay
  • 137
  • 1
  • 11
  • okay thanks, but if the value comes to the parameter it sems like nothing in there but in the url i can see the parameter do you know why? parameter is string in controller but item.Parameter is object. – Amsel Mar 22 '17 at 08:45
  • 1
    Omg sry ignor my comment it was because name of parameter wasn't the same haha, thanks for the awnser btw. – Amsel Mar 22 '17 at 08:57