0
我有一個ASP.NET MVC 4項目與EF和我有一個驗證問題的視圖與我的一些領域。 我已經注意到,ValidationMessageFor僅適用於我的十進制領域ValidationMessageFor mvc只能使用十進制
<script type="text/javascript" language="javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script type="text/javascript" language="javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>
@using (Html.BeginForm("Create", "Order", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<div class="editor-label">
@Html.Label("Adresa livrare")
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.adresa, new { maxlength = "80" }) @*string - nvarchar*@
@Html.ValidationMessageFor(model => model.adresa)
</div>
<div class="editor-label">
@Html.Label("Curs Euro")
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.curs_euro, new { onkeypress = "return numericOnly(this)", id = "euro", maxlength = 9 }) @*decimal - decimal(10,2)*@
@Html.ValidationMessageFor(model => model.curs_euro, Resources.Global.strCursEuroV)
</div>
問:爲什麼驗證不工作的字符串字段?
我試圖裝飾我的模型設計師,並添加[必需],但它搞亂了我的所有項目。
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
[Required(ErrorMessage = "validation messeage...")]
public global::System.String adresa
HTML
<div class="editor-label">
<label for="Adresa_livrare">Adresa livrare</label>
</div>
<div class="editor-field">
<input id="adresa" maxlength="80" name="adresa" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="adresa" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Curs_Euro">Curs Euro</label>
</div>
<div class="editor-field">
<input data-val="true" data-val-number="The field curs_euro must be a number." data-val-required="The curs_euro field is required." id="euro" maxlength="9" name="curs_euro" onkeypress="return numericOnly(this)" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="curs_euro" data-valmsg-replace="false">Introduceti cursul Euro</span>
</div>
你有 <添加鍵= 「ClientValidationEnabled」 值= 「真」/> <添加鍵= 「UnobtrusiveJavaScriptEnabled」 值=「真「/> appSettings> 在您的網絡配置? –
Dan
是的,我有他們。驗證適用於我的小數字段。 – Misi
您是否試圖用設計器生成的屬性代碼進行裝飾? – objectbox