asp.net mvc - View 和 Controller

标签 asp.net asp.net-mvc viewusercontrol

Controller 如何知道要返回哪些 View ?我认为这是按照命名约定,但我见过一些实例,例如在 Nerd Dining 应用程序中,名称不匹配。在哪里或如何查看此映射?谢谢。

最佳答案

public class EmployeesController
{
    public ViewResult Index()
    {
        return View("CustomerName");
    }
}

将搜索:

Views/Employees/CustomerName.aspx
Views/Employees/CustomerName.ascx
Views/Shared/CustomerName.aspx
Views/Shared/CustomerName.ascx

差不多就是这样了..

当你刚刚返回View()时;在不指定名称的情况下,它会搜索与 Controller 操作同名的 View 。在本例中,Index.aspx

关于asp.net mvc - View 和 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1239308/

相关文章:

asp.net - 即使启用了Windows身份验证,HttpContext.Current.User也为null

c# - 名称 'html' 也不存在于用户控件 MVC 和 C# 的当前上下文中的名称 'model'

asp.net-mvc - T4MVC 不支持 DisplayTemplates 和 EditorTemplates

jquery - 使用 ASP.NET MVC 和 AJAX 的分页表

c# - MVC Ajax.error 渲染部分 View

c# - 授权属性中的角色在 MVC 4 中无法按预期工作

c# - 带有使用 MVC 1.0 的 Controller 的 ASP.Net MVC ViewUserControl

c# - ASP.NET 日期和时间选择器?

c# - 具有自动生成列的可编辑 GridView

c# - 显示/插入特殊字符的问题,MySql ASP.NET