2

或者也许是相反的方式?

我是新的 MVC,所以要温柔。我可以从 a 中选择一个值,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 错误。它该死的烦人=)

4

0 回答 0