【发布时间】:2015-11-27 15:46:28
【问题描述】:
我有一个 MVC 5 应用程序。我正在尝试使用我的 viewmodel 属性应用验证。例如。我的字段是必需的。但是由于某种原因,在用户可以输入任何内容之前,最初会显示空字段上的错误。你能解释一下吗?
@Html.ValidationSummary(false, "Please fix the errors:", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.FileToUpload, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("FileToUpload", "", new { @type = "file", @class = "input-xlarge form-control" })
@Html.ValidationMessageFor(model => model.FileToUpload, "*", new { @class = "text-danger" })
</div>
</div>
...
public ActionResult Index()
{
return View();
}
我仅将我的视图模型用于验证目的,因此它不会传递给视图。
【问题讨论】: