我的前端验证似乎已停止在我的网站上,即使我创建新的控制器+查看我的所有表单,当点击直接发布到服务器而不检查本地生成(MVC框架内置的默认jqueryval验证)。这将返回到抛出的表达式,但它表示尝试更新时存在验证错误。
我很高兴提供源代码,但说实话,我不确定究竟是什么,这才真正开始本周。我倾向于不更新的东西(不确定),但任何帮助将不胜感激。评论如果您想查看特定代码,将很乐意更新问题。
控制器POST:
// POST: Codes/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind(Include = "id,CountryId,TPrintBw,TPrintCol,TCopyBw,TCopyCol,TFax,TScan")] Code code)
{
if (ModelState.IsValid)
{
try
{
db.Codes.Add(code);
await db.SaveChangesAsync();
return RedirectToAction("Index");
}
catch (Exception e)
{
}
}
ViewBag.CountriesList = new SelectList(db.Countries.ToList(), "NumCode", "CountryName");
return View(code);
}
创建RAZOR:
@model regusPrintMan.Models.Code
@{
ViewBag.Title = "Edit";
ViewBag.Section = "Country Codes";
}
@section Styles {
<!-- BEGIN PAGE LEVEL STYLES -->
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/select2/select2.css" />
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css" />
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css" />
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/datatables/extensions/Scroller/css/dataTables.scroller.min.css" />
<link rel="stylesheet" type="text/css" href="../../assets/global/plugins/datatables/extensions/ColReorder/css/dataTables.colReorder.min.css" />
<!-- END PAGE LEVEL STYLES -->
}
@section JS {
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script type="text/javascript" src="../../assets/global/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/extensions/ColReorder/js/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="../../assets/global/plugins/datatables/extensions/Scroller/js/dataTables.scroller.min.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="../../assets/global/scripts/datatable.js"></script>
<script src="../../assets/admin/pages/scripts/table-ajax.js"></script>
<!-- END PAGE LEVEL SCRIPTS -->
<script>
jQuery(document).ready(function () {
Layout.init(); // init current layout
Demo.init(); // init demo features
TableAjax.init();
});
</script>
<!-- END JAVASCRIPTS -->
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
<!-- BEGIN PAGE HEAD -->
<div class="page-head">
<div class="container">
<!-- BEGIN PAGE TITLE -->
<div class="page-title">
<h1>@ViewBag.Section <small></small></h1>
</div>
<!-- END PAGE TITLE -->
</div>
</div>
<!-- END PAGE HEAD -->
<!-- BEGIN PAGE CONTENT -->
<div class="page-content">
<div class="container">
<!-- BEGIN PAGE CONTENT INNER -->
<div class="row">
<div class="col-md-12">
<!-- Begin: life time stats -->
<div class="portlet light">
<div class="portlet-title">
<div class="caption">
<i class="fa fa-gift font-green-sharp"></i>
<span class="caption-subject font-green-sharp bold uppercase">Create Country Codes</span>
</div>
<div class="tools">
</div>
</div>
<div class="portlet-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CountryId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.CountryId, (SelectList)ViewBag.CountriesList, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CountryId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TPrintBw, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TPrintBw, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TPrintBw, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TPrintCol, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TPrintCol, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TPrintCol, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TCopyBw, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TCopyBw, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TCopyBw, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TCopyCol, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TCopyCol, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TCopyCol, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TFax, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TFax, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TFax, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TScan, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.TScan, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.TScan, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
</div>
</div>
</div>
</div>
<!-- END PAGE CONTENT INNER -->
</div>
</div>
<!-- END PAGE CONTENT -->