Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc MVC中的验证?_Asp.net Mvc_Validation - Fatal编程技术网

Asp.net mvc MVC中的验证?

Asp.net mvc MVC中的验证?,asp.net-mvc,validation,Asp.net Mvc,Validation,在我的项目中,验证消息没有显示,没有得到任何错误,只是消息没有显示。什么是错误 以下是模型、视图和控制器的部分代码: public ActionResult Index() { return View(); } 型号: [Required(ErrorMessage = "Username is required")] public string Username { get; set; } [Required(ErrorMessage = "Password is r

在我的项目中,验证消息没有显示,没有得到任何错误,只是消息没有显示。什么是错误

以下是模型、视图和控制器的部分代码:

 public ActionResult Index()
 { 
     return View();
 }
型号:

 [Required(ErrorMessage = "Username is required")]
 public string Username { get; set; }

 [Required(ErrorMessage = "Password is required")]
 public string Password { get; set; }
控制器:

 public ActionResult Index()
 { 
     return View();
 }
视图:


用户名
@Html.TextBoxFor(model=>model.Username,新的{@class=“form control”,placeholder=“请输入您的用户名”,@style=“height:45px”})
@Html.ValidationMessageFor(m=>m.Username,“,new{@class=“text danger”})
密码
@Html.TextBoxFor(model=>model.Password,新的{@class=“form control”,placeholder=“请输入您的密码”,@style=“height:45px”})
@Html.ValidationMessageFor(m=>m.Password,“,new{@class=“text danger”})

我猜您没有包括“jquery.unobtrusive ajax.min.js”和/或“jquery.validate.unobtrusive.min.js”。我相信这些是解释DataAnnotations添加的元数据和提供您需要的验证方法所必需的

请参阅此链接以获得更好的理解


我必须同时包括这两个吗?不包括任何人