数据注释不适用于所选的jquery插件

时间:2014-08-25 17:34:08

标签: asp.net-mvc-4 data-annotations jquery-chosen html.dropdownlistfor

我有一个包含多个htmlhelper控件的表单,如文本框和下拉列表。我已经使用数据注释对各个字段进行验证,并使用qtip来显示验证消息。我也使用了所选的jquery插件来增强UI。如果选择了插件调用,则数据注释不起作用。验证为itemlist工作,但不适用于其他两个..请帮助任何输入。这是我的代码:

我的观点 IndentItem.cshtml

if (ViewBag.isCreate == true)
 {
    <td>
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.IndentId)
        @Html.HiddenFor(model => model.ItemCode)
        @Html.HiddenFor(model => model.ItemType)

        @Html.DropDownListFor(model => model.DepartmentMachineId, Model.DepartmentMachineList, new { @class = "machineList input-medium" })
        @Html.ValidationMessageFor(model=>model.DepartmentMachineId)
    </td>
    <td>
        @Html.DropDownListFor(model => model.ItemName, Model.ItemNameList, new { @class = "itemList input-medium" })
    </td>
    <td>
        @Html.DropDownListFor(model => model.CategoryName, Model.CategoryNameList, new { @class = "catList input-medium" })
    </td>
    <td>
        @Html.DropDownListCustomFor(model => model.ItemId, Model.ItemCodeList, new { @class = "codeList input-medium" })
    </td>
    <td>
        @Html.TextBoxFor(model => model.ItemUnitDescription, new { placeholder = "unit type", @class = "input-small", @readonly = "true" })
    </td>
    <td>
        @Html.TextBoxFor(model => model.RequestedQuantity, new { placeholder = "quantity", @class = "input-small" })
    </td>

<div class="form-actions">
<button type="submit" class="btn btn-blue" >Save changes</button>`</div>

我的模特

public class IndentItem
{
    /// <summary>
    /// Autogenerated Purchase Indent ID
    /// </summary>
    [DisplayName("S.No")]
    [DataType(DataType.Text)]
    [StringLength(10)]
    [Editable(false)]
    [Required(ErrorMessage = "S.No Required")]
    [Key()]
    public string Id { get; set; }

    [DataType(DataType.Text)]
    [Editable(false)]
    [Required(ErrorMessage = "Indent Id Required")]
    public string IndentId { get; set; }

    /// <summary>
    /// machine number
    /// </summary>
    [DisplayName("Machine number")]
    [DataType(DataType.Text)]
    [StringLength(50)]
    [Editable(true)]
    [Required(ErrorMessage = "Machine number Required")]
    public string DepartmentMachineId { get; set; }
    public IEnumerable<SelectListItem> DepartmentMachineList { get; set; }

    /// <summary>
    /// Item name
    /// </summary>
    [DisplayName("Item name")]
    [DataType(DataType.Text)]
    [StringLength(50)]
    [Editable(true)]
    [Required(ErrorMessage = "Item name Required")]
    public string ItemName { get; set; }

    [DisplayName("Item ID")]
    [DataType(DataType.Text)]
    [StringLength(50)]
    [Editable(true)]
    [Required(ErrorMessage = "Item ID Required")]
    public string ItemId { get; set; }

    /// <summary>
    /// Type of units
    /// </summary>
    [DisplayName("???")]
    [DataType(DataType.Text)]
    [StringLength(50)]
    [Editable(true)]
    public string ItemType { get; set; }

    public string ItemUnitDescription { get; set; }

    /// <summary>
    /// Category
    /// </summary>
    [DisplayName("Category")]
    [DataType(DataType.Text)]
    [StringLength(50)]
    [Editable(true)]
    [Required(ErrorMessage = "Category Required")]
    public string CategoryName { get; set; }

    /// <summary>
    /// List of possible categories
    /// </summary>
    [DisplayName("Category")]
    public IEnumerable<SelectListItem> CategoryNameList { get; set; }

    /// <summary>
    /// Item code
    /// </summary>
    [DisplayName("Item code")]
    [DataType(DataType.Text)]
    [StringLength(50)]
    [Editable(true)]
    [Required(ErrorMessage = "Item code Required")]
    public string ItemCode { get; set; }

    /// <summary>
    /// List of possible Item codes
    /// </summary>
    [DisplayName("Item code")]
    public IEnumerable<SelectListItemEx> ItemCodeList { get; set; }

    /// <summary>
    /// number of items
    /// </summary>
    [DisplayName("Required quantity")]
    [Range(typeof(int), "1", "100000")]
    [DataAnnotationsExtensions.Integer(ErrorMessage = "Please enter a positive whole number.")]
    [Required(ErrorMessage = "Required")]
    public int RequestedQuantity { get; set; }

    /// <summary>
    /// number of items
    /// </summary>
    [DisplayName("Issued")]
    [Range(typeof(int), "0", "100000")]
    [DataAnnotationsExtensions.Integer(ErrorMessage = "Please enter a positive whole number.")]
    [Editable(true)]
    public int IssuedQuantity { get; set; }

    /// <summary>
    /// number of items
    /// </summary>
    [DisplayName("Balance")]
    [Range(typeof(int), "0", "100000")]
    [DataAnnotationsExtensions.Integer(ErrorMessage = "Please enter a positive whole number.")]
    [Editable(true)]
    public int BalanceQuantity { get; set; }

    /// <summary>
    /// number of items returned
    /// </summary>
    [DisplayName("Return")]
    [Range(typeof(int), "0", "100000")]
    [DataAnnotationsExtensions.Integer(ErrorMessage = "Please enter a positive whole number.")]
    [Editable(true)]
    public int ReturnQuantity { get; set; }

    public IEnumerable<SelectListItemEx> ItemList { get; set; }
    public IEnumerable<SelectListItem> ItemNameList { get; set; }   


    }
}
  $(".itemList").change(GetItemCategories);
    $(".catList").chosen().change(GetItems);
    $(".codeList").chosen().change(SetItem);

0 个答案:

没有答案