【问题标题】:How to create menu link in ASP.NET MVC with Area?如何在带有区域的 ASP.NET MVC 中创建菜单链接?
【发布时间】:2021-10-29 18:18:23
【问题描述】:

我将菜单链接保存在我的数据库中,格式为:“master/country”,master 是区域名称,country 是控制器名称。我的网址是 http://localhost/appname。当我单击国家菜单时,它会重定向到国家页面(http://localhost/appname/master/country)。但是当我再次单击 City 菜单项(也在主区域中)时,它会重定向到 http://localhost/appname/ma​​ster/master/city。我在StringBuilder(包括标签)中编写菜单链接并将其存储在viewbag

我尝试将菜单链接更改为“/master/country”,然后当我单击第一个菜单(国家/地区)时,URL 变为 http://localhost/master/country。

我正在使用 MVC 5。如何在同一区域内创建链接菜单?

【问题讨论】:

    标签: c# asp.net-mvc


    【解决方案1】:

    这将有助于从操作链接访问area

    @Html.ActionLink("MyText", "ActionName", "ControllerName", new { area = "YourAreaName"}, null)
    

    这将help you more options on SO

    或者您使用上面的链接创建一个由控制器指定的区域

    Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{})
    

    【讨论】:

    • 我在不同的项目中创建方法。我认为 Html.ActionLink 和 Html.ActionLink 必须在 System.Web.Mvc.Controller 类中。如何在不同的项目中调用 HtmlActionLink ?
    【解决方案2】:

    你可以试试这个方法

     return RedirectToAction("ActionName", "ControllerName", new { area = "AreaName" });
    

    【讨论】:

      猜你喜欢
      • 2011-04-27
      • 1970-01-01
      • 2010-10-04
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 2022-07-24
      相关资源
      最近更新 更多