В моем классе есть эти два свойства:
Код: Выделить всё
[StringLength(500, ErrorMessage = "{0} can have a max of {1} characters")]
public string MyProperty { get; set; }
[StringLength(100, ErrorMessage = "{0} can have a max of {1} characters")]
public string MyOtherProperty { get; set; }
Код: Выделить всё
@Html.TextBoxFor( m => m.MyProperty )
@Html.TextBoxFor( m => m.MyOtherProperty )
@using (Html.BeginScripts()) {
$(function () {
MyScriptModule.Init();
}); // end of document.ready
}
Код: Выделить всё
var $form = $("#MyForm");
var $submit = $("#Save");
var MyScriptModule = (function () {
var init = function () {
$submit.bind("click", function () {
HandleSubmitLogic();
});
// Initialize form validation
$form.validate({
ignore: [],
rules: {
MyOtherProperty: {
required: function (element) {
return $("#MyProperty").val().length > 0;
}
}
},
errorPlacement: function (error, element) {
error.appendTo(element.parent());
},
});
}; // end init
function HandleSubmitLogic() {
$submit.prop("disabled", true);
ResetFormValidation($form);
$form.validate();
if ($form.valid()) {
$form.submit();
}
$submit.prop("disabled", false);
}
}
Так что же я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/787 ... -not-empty