重写控制器操作方法的 URL
我有一个名为 Person 的控制器,它有一个名为 NameSearch 的 post 方法。
此方法返回 RedirectToAction("Index")、View("SearchResults") 或 View("Details")。 我得到的所有 3 种可能性的网址是 http://mysite.com/Person/NameSearch。 我如何更改此设置以将 URL 重写为 http://mysite.com/Person/Index 以进行 RedirectToAction (“索引”),http://mysite.com/Person/SearchResults 用于查看(“SearchResults” ),以及 http://mysite.com/Person/Details 用于查看(“详细信息”)。
提前致谢
I have a controller called Person and it has a post method called NameSearch.
This method returns RedirectToAction("Index"), or View("SearchResults"), or View("Details").
The url i get for all 3 possibilities are http://mysite.com/Person/NameSearch.
How would i change this to rewrite the urls to http://mysite.com/Person/Index for RedirectToAction("Index"), http://mysite.com/Person/SearchResults for View("SearchResults"), and http://mysite.com/Person/Details for View("Details").
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的
NameSearch
函数评估查询结果并根据以下条件返回这些结果:因此,您的控制器或多或少会如下所示:
因此,您可能需要定义路由,以便:
Index
操作结果将由默认的{controller}/{action} 处理/{id}
路线。这推动你走向正确的方向?
I'm assuming your
NameSearch
function evaluates the result of a query and returns these results based on:So, more of less your controller would look like:
So, you would probably need to define routes such that:
The
Index
action result will be handled by the default{controller}/{action}/{id}
route.That push you in the right direction?