找不到模型 [英] Model could not be found

查看:135
本文介绍了找不到模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经包含了一个模型,并创建了一个视图文件以及一个控制器来指导所有这些人

I have included a model and created a view file as well as a controller to direct all of them

public class CreateNewUserModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required(ErrorMessage = "Email required")]
    [EmailAddress(ErrorMessage = "Not a valid email")]
    public string UserEmail { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }

    [Required]
    [Display(Name = "Role")]
    public string UserRole { get; set; }
    public IEnumerable<System.Web.Mvc.SelectListItem> UserRoles { get; set; }
}

在查看文件顶部

我也有@model CreateNewUserModel

这是我遇到的编译错误

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0246: The type or namespace name 'CreateNewUserModel' could not be found (are you missing a using directive or an assembly reference?)

 Source Error:   
Line 32:     
Line 33:     
Line 34:     public class _Page_Views_Account_CreateNewUser_cshtml : System.Web.Mvc.WebViewPage<CreateNewUserModel> {
Line 35:         
Line 36: #line hidden 

推荐答案

您只需要完全指定模型类型的名称或导入模型的名称空间即可.

You just need to either fully specify the name of the model type or import the namespace for the model.

例如

@model MyNamespace.CreateNewUserModel

@using MyNamespace
@model CreateNewUserModel

很明显,将上面示例中的"MyNamespace"替换为定义模型类的名称空间.

Obviously, replace "MyNamespace" in the examples above with the namespace in which you defined your model class.

这篇关于找不到模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆