为Html.ActionLink添加Area属性无效的问题求助
解决.NET Core中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
相关产品推荐
相关产品推荐

