보기에서 원격 유효성 검사를 사용하고 있으며 완벽하게 작동합니다. 내가 가진 문제는 제출 버튼을 클릭해도 아무 것도 일어나지 않고 원격 유효성 검사가있는 필드로 포커스가 되돌아갑니다. 양식이 제출되지 않습니다.데이터 저장시 원격 확인 유효성 확인 버튼이 표시되지 않습니다.
원격 유효성 확인을 설정하려면이 페이지 (https://msdn.microsoft.com/en-us/library/gg508808(VS.98).aspx)를 참조했습니다. 사용 가능한 최신 것이 있는지 확실하지 않습니다.
모델에서 [Remote]
을 제거하면 제대로 제출됩니다. 내가 뭘 잘못하고 있니?
내 모델은
public class Doctor
{
[Remote("checkEmployeeNumber", "Doctors")]
public string EmployeeNumber { get; set; }
public string DoctorSurname { get; set; }
public string DoctorGivenName { get; set; }
}
감사관입니다
보기@model WebApplication1.Models.Doctor
@{
ViewBag.Title = "Create";
}
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<h2>New Doctor Entry</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.DoctorSurname, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DoctorSurname, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DoctorSurname, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EmployeeNumber, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EmployeeNumber, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EmployeeNumber, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DoctorGivenName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DoctorGivenName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DoctorGivenName, "", 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>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
는 또한 추가 한
public ActionResult checkEmployeeNumber(string EmployeeNumber)
{
if (EmployeeNumber == null)
{
return Json(false, JsonRequestBehavior.AllowGet);
}
Doctor doctor = db.Doctors.Find(EmployeeNumber);
if (doctor == null)
{
return Json(false, JsonRequestBehavior.AllowGet);
}
return Json(true, JsonRequestBehavior.AllowGet);
}
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
,691,363을의 Web.config하려면 다음210