如何处理 MVC 中的相对路由?

How to handle relative routing in MVC?

我是 MVC 的新手,我的系统中有一个特定的默认路由:

routes.MapRoute(
  name: "Default",
  url: "{controller}/{action}/{id}",
  defaults: new { controller = "Employee", action = "Index", id = UrlParameter.Optional }
);

现在,由于它默认为 Employee/Index,localhost:// 和 localhost://Employee/Index 都将转到相同的默认页面位置。到目前为止,一切都很好。现在,

我有一些方法可以通过单击 KendoUI 选项卡控件动态调用部分视图,代码如下所示:

tabstrip.Add()
  .Text("Details")
  .Selected(true)
  .LoadContentFrom("Employee/ShowEmployeeProfileInfo/" + @Model);

就我在 Localhost:// 上而言,它工作正常。但是,当我在 localhost/Employee/Index 上时它不起作用,因为它试图浏览到 locahost/employee/Employee/ShowEmployeeProfileInfo(注意到两个 "Employee(s) in the route?")

我认为我配置路径的方式有问题,或者可能是我浏览它的方式有问题。有什么想法吗?

您缺少前导正斜杠。它需要是 "/Employee/ShowEmployeeProfileInfo...,但是建议使用 @Url.Action() 来生成链接

.LoadContentFrom('@Url.Action("ShowEmployeeProfileInfo", "Employee", new { id = Model })');