我有我的看法如下HTML:MVC驗證 - [必需]屬性拋出的jQuery JSON.parse異常
@model PatientLookupModel
@if (Model.IsModelInvalid)
{
@Html.ValidationSummary(false, Model.Resources.InvalidFormMessage)
}
@using (Html.BeginForm("Lookup", "Patient", FormMethod.Post, new { role = "form" }))
{
@Html.Label(Model.Resources.PatientFirstNameLabel)
@Html.TextBoxFor(m => m.PatientFirstName, new { @class = "form-control" })
}
我的模型看起來是這樣的:
using RESOURCES = AppResources.Resources;
namespace Models
{
public class PatientLookupModel
{
[Required(ErrorMessageResourceType = typeof(RESOURCES), ErrorMessageResourceName = "Patient_Lookup_PatientFirstNameRequiredMessage")]
public string PatientFirstName { get; set; }
}
}
我BundleConfig看起來是這樣的:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/lib/jquery-{version}.js",
"~/scripts/lib/jquery.unobtrusive*",
"~/Scripts/lib/jquery.validate*",
"~/Scripts/lib/jquery.maskedinput.js"));
表單本身按預期工作。當沒有輸入名字時,頁面會重新加載填充的驗證摘要。問題是,當你鍵入的第一個名字輸入的東西,然後它失去焦點,一個例外是在瀏覽器控制檯拋出:
data
是不確定的。
任何想法?
http://stackoverflow.com/a/14822755/1893261看看這篇文章,讓我知道它是否有幫助。 – 2014-09-08 13:02:21
@ShukhratRaimov:我以前曾嘗試加載jquery的早期版本(我使用1.11.1),並注意到它有不同的行爲。使用1.11.1,它實際上會回發,但版本<1.9只是將錯誤類應用到元素並將它們放在焦點上。我不確定這種行爲是否可以接受。 – im1dermike 2014-09-08 13:56:18