0

I try create dynamic menu but i have problem with adding parameters in link to the controller and action, can i add parameter to url.content? or there are the other way please give your insight it will very helpfull

<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">Menu Example</a>
        </div>
        <ul class="nav navbar-nav">
            @if (Session["Menu"] != null)
            {

                var MenuMaster = (List<Accountstatement.Models.MenuModel>)Session["Menu"];
                var groupByMenu = MenuMaster.GroupBy(x => x.MainMenuName).ToList();

                foreach (var MenuList in groupByMenu)
                {

                    <li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">@MenuList.Key<span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            @foreach (var SubMenuList in MenuList)
                            {
                                <li><a href="@Url.Content("~/"+@SubMenuList.ControllerName +"/"+ @SubMenuList.ActionName")">@SubMenuList.SubMenuName</a></li>
                            }
                        </ul>
                    </li>

                }
            }

        </ul>

this is the part the url.content is, how can i put the parameter inside url.content?

<li><a href="@Url.Content("~/"+@SubMenuList.ControllerName +"/"+ @SubMenuList.ActionName")">@SubMenuList.SubMenuName</a></li>
omik
  • 27
  • 6
  • Totally unrelated to what the question is asking but check out https://stackoverflow.com/questions/8186163/mvc-url-content-vs-url-action as it may be more in line of what you are doing... – Alexei Levenkov Feb 22 '21 at 07:34

1 Answers1

0

Use @Html.Raw with Url.Content and pass parameters like below:

@Html.Raw(Url.Content("~/"+@SubMenuList.ControllerName +"/"+ @SubMenuList.ActionName?param=" + param.value))

Farzad
  • 28
  • 7