jquery.validate.unobtrusive.js正在杀死我的selectList()

时间:2013-01-29 04:02:02

标签: jquery asp.net-mvc-4 jquery-validate unobtrusive-validation

或许反过来呢?

我是新MVC所以要温柔。我可以从Html.DropDownList中选择一个值,并在保存时填充到模型中。但是,如果我单击开箱即用jQuery.Validate对我咆哮,并显示有关空数据的错误。

这是错误

+       this    function( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context, rootjQuery );
    }   Object, (Function)

这是视图

@model Game.Domain.Equipment

<div class="editor-label">
    @Html.LabelFor(model => model.BaseGameObject.Name)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.BaseGameObject.Name) @Html.ValidationMessageFor(model => model.BaseGameObject.Name)
</div>

<div class="editor-label">
    @Html.LabelFor(model => model.BaseGameObject.Description)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.BaseGameObject.Description) @Html.ValidationMessageFor(model => model.BaseGameObject.Description)
</div>

<div class="editor-label">
    @Html.LabelFor(model => model.Type)
</div>

<div class="editor-field">
    @Html.DropDownListFor(model => model.Type, new SelectList(Enum.GetValues(typeof(Game.Domain.EquipmentType))))
</div>

<div class="editor-label">
    @Html.LabelFor(model => model.Value)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Value) @Html.ValidationMessageFor(model => model.Value)
</div>

这是模型

namespace Game.Domain
{
    public class Equipment
    {
        public Equipment()
        {
            BaseGameObject = new BaseGameObject();
        }

        public virtual int Id { get; set; }
        public virtual BaseGameObject BaseGameObject { get; set; }
        public virtual EquipmentType Type { get; set; }

        public virtual int Value { get; set; }
    }
}

我试图用jquery

关闭jvalidate jquery
$(function () {
    var select = $('select');
    $('select').attr("willValidate", false)
});

但无论我尝试什么,我一遍又一遍地得到相同的jvalidate错误。它该死的烦人=)

0 个答案:

没有答案