gpt4 book ai didi

c# - 找不到模型

转载 作者:太空狗 更新时间:2023-10-29 20:03:12 27 4
gpt4 key购买 nike

我已经包含了一个模型并创建了一个 View 文件以及一个 Controller 来控制所有这些

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; }
}

在 View 文件之上

我还有@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

最佳答案

您只需完全指定模型类型的名称或导入模型的命名空间。

例如

@model MyNamespace.CreateNewUserModel

@using MyNamespace
@model CreateNewUserModel

显然,将上面示例中的“MyNamespace”替换为您在其中定义模型类的命名空间。

关于c# - 找不到模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14676269/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com