【发布时间】:2014-11-19 11:09:13
【问题描述】:
我正在使用 MVC4 创建一个表单。 这里我使用了剑道多选并尝试通过模型注释进行验证。
我的代码是:
@model WEBAPP._2012.Models.DeviceInventory.DeviceTechnologyModel
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
@using (Ajax.BeginForm("Create", "Device_TechnologyInventory", new AjaxOptions { HttpMethod = "POST", OnSuccess = "onSuccessAddTechnology" })) { @Html.ValidationSummary(true)
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<@Html.LabelFor(model=>model.Name)</td>
<td class="editor-field" width="160px;">
@Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name)
</td>
</tr>
<tr>
<td>@Html.LabelFor(model => model.Alias)</td>
<td class="editor-field">
@Html.EditorFor(model => model.Alias) @Html.ValidationMessageFor(model => model.Alias)
</td>
</tr>
<tr>
<td>@Html.LabelFor(model => model.Vendors)/td>
<td class="editor-field">
@(Html.Kendo().MultiSelectFor(model=>model.Vendors) .Name("Vendors").Placeholder("Select") .BindTo(new SelectList(ViewBag.VendorList, "Value", "Text")) ) @Html.ValidationMessageFor(model => model.Vendors)
</td>
</tr>
</table>
<div class="CreateWrp">
<input type="submit" value="Create " class="btn-success"/>
<input type="reset" value="Reset " class="btn-primary" />
</div>
我的模型是:
public class DeviceTechnologyModel
{
public int Id { get; set; }
[Required(ErrorMessage = "*")]
[Display(Name = "Device Technology")]
public string Name { get; set; }
[Required(ErrorMessage = "*")]
[Display(Name = "Alias")]
public string Alias { get; set; }
[Required(ErrorMessage = "*")]
[Display(Name = "Device vendors")]
public List<string> Vendors { get; set; }
}
当我点击提交按钮时,验证错误消息同时出现在“名称”和“别名”字段上,但不在“供应商”字段上。
我不想使用javascript 验证。
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-4 kendo-ui data-annotations