提交一次表单,但在POST方法中自动加倍/两次?ASP.NET MVC



我目前正在用asp.net(v4.6(mvc(v5(开发一个项目,它在远程服务器上的第一次部署时工作正常,在第一次测试之后,当我用POST方法提交时,它在表单上给出了错误。它会自动将表单过帐两次,这是不需要的。

我检查错误的地方:

  1. 源代码(同时也是DEBUG(
  2. 已搜索并尝试的日志
  3. 使用工具检查此问题发生的原因和来源(无结果(

我修复了我发现的浏览器问题,当我从chrome更改为edge时没有错误。。。但仍然没有关于错误是什么以及如何生成的注释。

这是View.cshtml

@using (Html.BeginForm("Create", "AdmissionCell", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="col-md-12">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@*Input Fields Here*@
<div class="form-group">
<div class="col-md-offset-4 col-md-6">
<input type="submit" value="Save Student Record" class="btn btn-primary btn-lg" />
</div>
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$(document).ready(function () {
$("#CNIC").change(function () {
$.get("/AdmissionCell/CheckCNIC",
{ cnic: $("#CNIC").val() },
function (data) {
if (data === 1) {
//alert("Sorry, CNIC already exists, Please enter unique CNIC. or ");
//location.reload();
var cnicStu = $("#CNIC").val();
if (window.confirm('Sorry, CNIC already exists, Please enter unique CNIC or Press "Ok" to goto student details.')) {
window.location.href = "/AdmissionCell/Details?cnic=" + cnicStu;
};
}
});
});
});
</script>
<script>
$(function () {
$('.cnic').on('keyup', function () {
var input = $('.cnic').val();
if (input.length == 5 || input.length == 13) {
$('.cnic').val(input + '-');
}
});
$('.gcnic').on('keyup', function () {
var input = $('.gcnic').val();
if (input.length == 5 || input.length == 13) {
$('.gcnic').val(input + '-');
}
});
});
</script>
}

我怀疑您的jqueryval捆绑包包含了两次。

一旦在视图中(如图所示(,也在_layout文件中,因此事件被绑定两次

最新更新