如何重定向到索引 actionresult 而不是在 url 中显示索引

Jam*_*meo 1 c# asp.net visual-studio asp.net-mvc-4

基本上,在我的控制器中,我重定向到 Index 操作:

return RedirectToAction("", new { id = id });
Run Code Online (Sandbox Code Playgroud)

除了 URL 栏显示controllername/index/id. 我希望能够避免在 URL 中显示“索引”。这可能吗?如果是这样,如何?

DGi*_*bbs 5

在您的global.asax.cs:

routes.MapRoute("NoActionInURL", "ControllerName/{id}", 
       new { controller = "ControllerName", action = "Index", id = UrlParameter.Optional });
Run Code Online (Sandbox Code Playgroud)