如何更改已映射到 ASP.NET MVC3 中操作方法的视图的名称
我有一个使用 C# 和 Razor 开发的 ASP.NET MVC3 应用程序。
我有一个视图,View1,映射到操作方法,ActionMethod1。为了尊重命名约定,我想将 View1 重命名为 View2 并仍然将其映射到相同的操作方法。
问题是,当我将名称更改为 View2 时,ActionMethod1 不再识别视图。
我知道我可以显式指定视图的名称作为重载方法 View(viewName, model)
中的第一个参数,但由于 之间已经存在映射ActionMethod1 和 View1 我发现这个解决方案相当“脏”。
如何让操作方法ActionMethod1明白它应该引用View2并放弃寻找View1?
I have an ASP.NET MVC3 application developed with C# and Razor.
I have a View, View1, mapped to and Action Method, ActionMethod1. In order to respect naming conventions I would like to rename View1 to View2 and still keep it mapped to the same action method.
The problem is that when I change the name to View2 the View is not anymore recognized by ActionMethod1.
I know that I can specify the name of the View explicitly as first parameter in the overload method View(viewName, model)
but since there is already a mapping between ActionMethod1 and View1 I found this solution quite "dirty".
How can I make the Action Method ActionMethod1 understand that it should refer to View2 and give up on looking for View1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该研究 ActionNameAttribute 。这将允许您更改操作的名称,尽管我认为您很可能必须使用显式返回的方法
才能获得您想要的结果。
I think you should look into the ActionNameAttribute. That will allow you to change the name of the action although I am thinking that you most likely will have to use the method where you explicitly return
in order to get the results you want.