我有一个这样的表格:
<div class="row">
@using (Ajax.BeginForm("ImportFromExcel", "QuanLySim", null, new AjaxOptions
{
UpdateTargetId = "div-form-daily",
HttpMethod = "POST",
OnBegin = "QuanLyDaiLy.BeforeSend",
OnFailure = "QuanLyDaiLy.Error",
OnComplete = "QuanLyDaiLy.Success",
InsertionMode = InsertionMode.Replace
}, new { @class = "form-update", @role = "form", @id = "search-form" }))
{
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="so-ct" class="col-xs-12 col-sm-12 col-md-2 input-sm">File excel <span class="text-red required">*</span></label>
<div class="col-xs-12 col-sm-12 col-md-10 input-sm">
@Html.TextBoxFor(model => model.File, new { type = "file", accept = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel", @class = "btn btn-default btn-sm", style = "width: 100%;" })
</div>
<div class="col-xs-12 col-sm-12 col-md-2"></div>
<div class="col-xs-12 col-sm-12 col-md-10 color-red" style="padding-left: 10px; margin-top: 10px">
@Html.ValidationMessageFor(model => model.File)
</div>
<div class="clear"></div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="so-ct" class="col-xs-12 col-sm-12 col-md-2 input-sm">Giá nhân thêm</label>
<div class="col-xs-12 col-sm-12 col-md-10 input-sm">
@Html.TextBoxFor(model => model.Rate, new { @class = "form-control input-sm", placeholder = "Nhập tỷ giá cho giá sim..." })
</div>
<div class="col-xs-12 col-sm-12 col-md-2"></div>
<div class="col-xs-12 col-sm-12 col-md-10 color-red" style="padding-left: 10px; margin-top: 10px">
@Html.ValidationMessageFor(model => model.Rate)
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="so-ct" class="col-xs-12 col-sm-12 col-md-2 input-sm">Chọn đại lý <span class="text-red required">*</span></label>
<div class="col-xs-12 col-sm-12 col-md-10 input-sm">
@Html.DropDownListFor(model => model.AgentId, (IEnumerable<SelectListItem>)ViewBag.Agents, "Chọn...", new { @class = "form-control input-sm add-daily-sim filter-select" })
</div>
<div class="col-xs-12 col-sm-12 col-md-2"></div>
<div class="col-xs-12 col-sm-12 col-md-10 color-red" style="padding-left: 10px; margin-top: 10px">
@Html.ValidationMessageFor(model => model.AgentId)
</div>
<div class="clear"></div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label for="so-ct" class="col-xs-12 col-sm-12 col-md-2 ">Đảm bảo đã đúng giá?</label>
<div class="col-xs-12 col-sm-12 col-md-1">
@Html.CheckBoxFor(model => model.IsSure.HasValue)
</div>
<label for="so-ct" class="col-xs-12 col-sm-12 col-md-2 ">Xóa sim đại lý</label>
<div class="col-xs-12 col-sm-12 col-md-1 ">
@Html.CheckBoxFor(model => model.IsXoaSimCu.HasValue)
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<div class="form-group">
<button type="button" class="btn bg-maroon btn-cons btn-sm" id="btn-import-excel">
<i class="fa fa-floppy-o fa-lg"></i> Lưu
</button>
<button class="btn btn-default btn-sm" type="button" onclick="location.href='@Url.Action("Index", "QuanLySim")'"><i class="glyphicon glyphicon-refresh fa-lg"></i> Quay về</button>
</div>
</div>
</div>
}
</div>
我打电话给jquery验证表格:
if (!$(form).valid()) return;
但是函数form.valid()是错误并在控制台中返回消息,如下所示: VM40309:1未捕获的SyntaxError:位于0的JSON中的意外标记u
每个人都可以帮我解决这个问题吗?
全部谢谢
答案 0 :(得分:0)
表单验证代码无法正常运行。请检查并在页面上使用不显眼的ajax作为参考: jquery.unobtrusive-ajax.min.js
答案 1 :(得分:0)
我认为这是与https://stackoverflow.com/a/14822755/1808720相同的问题 问题在于jQuery 1.9+和旧的jquery.validate.unobtrusive.js的组合。
从https://github.com/aspnet/jquery-validation-unobtrusive/releases下载最新版本的jquery.validate.unobtrusive.js,应该没问题。