2016-06-24 3 views
1

보기에서 원격 유효성 검사를 사용하고 있으며 완벽하게 작동합니다. 내가 가진 문제는 제출 버튼을 클릭해도 아무 것도 일어나지 않고 원격 유효성 검사가있는 필드로 포커스가 되돌아갑니다. 양식이 제출되지 않습니다.데이터 저장시 원격 확인 유효성 확인 버튼이 표시되지 않습니다.

원격 유효성 확인을 설정하려면이 페이지 (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

답변

1

2 일 동안 문제를보고 나서 질문을 제출 한 후 5 분 후에 해결책을 발견합니다! doh!

나는 두 개의 네가티브를 혼란스럽게 만들고있는 것 같습니다.

제 컨트롤러에서 어디에서 스위치를 돌리면 true이고 false인지 예상대로 작동합니다. 내가 기대하지 않은

한 것은 당신이 분야

  • 을 떠날 때 폼에 제출 버튼을 누르면 원격 유효성 검사가 두 번

    1. 활성화 될 것으로 보인다는 것이다.

    전송 버튼 확인이 필요하지 않았습니다.

    이 정보가 도움이되기를 바랍니다.