You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为Html.ActionLink添加Area属性无效的问题求助

问题根源

你当前的代码错误地将area参数放在了HTML属性的匿名对象里(最后一个参数),但在.NET Core中,路由相关的参数(包括Area)必须放在**路由值参数(第四个位置的匿名对象)**中,这是.NET Core和.NET Framework在Html.ActionLink参数处理上的关键区别。

修正后的代码

@Html.ActionLink("View", "Customer", "Accounts", new { CustomerID = Model.Customers[iRow].CustomerGUID, area = "Admin" }, new { @style = "", @class = "copy-01a" })

额外排查点

  • 确保目标控制器AccountsController上标注了[Area("Admin")]特性:
    [Area("Admin")]
    public class AccountsController : Controller
    {
        // 对应Action方法
        public IActionResult Customer(Guid customerID)
        {
            // 业务逻辑代码
        }
    }
    
  • 检查路由配置(通常在Program.cs或Startup.cs),确认包含Area路由模板:
    app.MapControllerRoute(
        name: "areas",
        pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
    );
    

内容的提问来源于stack exchange,提问作者Richard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 01:57:36