【发布时间】:2016-11-12 08:42:54
【问题描述】:
我有以下控制器:
public class MyController : BaseController
{
public ActionResult Index(string id) { /* Code */ }
public ActionResult MyAjaxCall(string someParameter) { /* Code */ }
}
我还在 RouteConfig.cs 中添加了以下内容
routes.MapRoute(
name: "MyController",
url: "MyController/{id}",
defaults: new { controller = "MyController", action = "Index" }
)
所以我的想法是能够使用这个 url /MyController/{Id} 直接进入索引操作,这似乎可行。
但是,在 Index 页面上,我需要对 /MyController/MyAjaxCall/{someParameter} 进行 Ajax 调用。然而,这个 url 指向 Index 控制器,并将 MyAjaxCall 解释为 Index 操作中的 id。
有什么想法可以从遵循新添加的路由配置设置中排除此操作吗?
【问题讨论】:
-
使用
url: "MyController/MyAjaxCall/{someParameter}"和defaults: new { controller = "MyController", action = "MyAjaxCall" }包含一个额外的路由
标签: c# asp.net-mvc routes url-routing asp.net-mvc-routing