【发布时间】:2017-09-18 11:34:23
【问题描述】:
我在 mvc 中工作。 这是我的看法:
@using (Html.BeginForm("CreatePost", "Posts", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "save-post-form" }))
{
<div class="row">
<div class="col-xs-5" id="post-details-div">
<div class="form-group">
<label>Post Title</label>
@Html.TextBoxFor(m => m.Title, new { @class = "form-control", @autocomplete = "off" })
@Html.ValidationMessageFor(m => m.Title, null, new { @class = "text-danger" })
</div>
<div class="form-group">
<label>Post Description</label>
@Html.TextAreaFor(m => m.Description, new { @class = "form-control", @autocomplete = "off" })
@Html.ValidationMessageFor(m => m.Description, null, new { @class = "text-danger" })
</div>
<div class="form-group">
<label>Post Cover Picture</label>
@Html.TextBoxFor(m => m.PostCoverFile, new { @type = "file" })
@Html.ValidationMessageFor(m => m.PostCoverFile, null, new { @class = "text-danger" })
</div>
</div>
<div id="post-content-div">
<label>Content</label>
<div class="form-group">
@Html.TextAreaFor(m => m.Content)
@Html.ValidationMessageFor(m => m.Content, null, new { @class = "text-danger" })
</div>
</div>
</div>
}
@section scripts{
<script>
require(["createPost"], function (module) {
$("#navbar-links").find("li[data-name='posts']").addClass('active');
module.load();
});
</script>
}
这是我的 js 文件。我只有表单验证。 我正在使用需要 js:
define(["jquery", "mainModule", "ckeditor", "jqueryValidateUnobtrusive", "bootstrapTagsInput", "typeAhead"], function ($, module, CKEDITOR) {
var bind = function () {
$(document).ready(function () {
console.log("ready");
$('#save-post-form').validate({
highlight: function (element) {
$(element).addClass('error');
$(element).removeClass('valid');
console.log("ceva");
},
unhighlight: function (element) {
$(element).removeClass('error');
$(element).addClass('valid');
console.log("ceva");
}
});
});
var createPostPage = {
load: function () {
bind();
}
}
return createPostPage;
});
什么也没发生,我不知道出了什么问题... 请帮我。验证有效,但高亮不会触发。
【问题讨论】:
标签: javascript jquery asp.net-mvc jquery-validate unobtrusive-validation