asp.net mvc - 视图和控制器
控制器如何知道要返回哪些视图? 我认为这是按照命名约定,但我见过一些实例,例如在 Nerd Dining 应用程序中,名称不匹配。 在哪里或如何查看此映射? 谢谢。
How do controllers know which views to return? I thought it was by naming convention, but I have seen instances, for example in the Nerd Dinner application, where the names don't match. Where or how do I see this mapping? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将搜索:
差不多就这样了..
当你只是 return View(); 时 在不指定名称的情况下,它会搜索与控制器操作同名的视图。 在本例中,Index.aspx
Will search for:
That's pretty much it..
When you just return View(); without specifying a name, it searched for the view with the same name as the controlleraction. In this case, Index.aspx
可以通过三种方式指定视图名称。
按约定
这将查找具有操作方法名称的视图,又名“MyAction.ascx”或“MyAction.aspx”
** 按名称 **
这将查找名为“MyViewName”的视图.ascx”或“MyViewName.aspx”。
** 按应用程序路径 **
这最后一个仅在这一个位置查找,即您指定的位置。
There are three ways to specify a view name.
By Convention
That will look for a view with the name of the action method, aka "MyAction.ascx" or "MyAction.aspx"
** By Name **
This will look for a view named "MyViewName.ascx" or "MyViewName.aspx".
** By application path **
This last one only looks in this one place, the place you specified.
它基于控制器中操作的名称。 这是一个示例:
我有一个名为 UserController 的控制器。
我对该控制器的操作之一名为 Index。
当我说 return View(); 时
它将在 Views 目录、User 文件夹中查找 Index.aspx 或 Index.ascx。
它还会在 Shared 文件夹中查找。
It is based on the name of the Action in the Controller. Here's an example:
I have a controller named UserController.
One of my actions on that controller is named Index.
When I say return View();
It will look in the Views directory, in the User folder, for Index.aspx or Index.ascx
It will also look in the Shared folder.