我有一個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();
}
我用我的視圖模型只是爲了進行驗證,所以它不會傳遞到視圖。
的可能的複製[ Html.ValidationSummary(假,「消息」)始終顯示,即使在頁面加載](http://stackoverflow.com/questions/4166997/html-validationsummaryfalse-message-is-always-showing-even-on-page-負載) – Ric