2016-06-24 5 views
1

私はビューでリモート検証を使用しています。私が持っている問題は、送信ボタンをクリックしても何も起きず、フォーカスがリモート検証を持っているフィールドに戻ってくるということです。フォームは決して送信されません。データを保存して送信ボタンを停止するリモート検証

リモート検証を設定するには、このページ(https://msdn.microsoft.com/en-us/library/gg508808(VS.98).aspx)を参照しました。使用可能なものがあるかどうかはわかりません。

モデルから[Remote]を削除すると正しく送信されます。 私は間違って何をしていますか?

私のモデルは、私はWeb.configファイル

<appSettings> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
</appSettings> 
に次のもを追加しました

public class Doctor 
{ 
    [Remote("checkEmployeeNumber", "Doctors")] 
    public string EmployeeNumber { get; set; } 
    public string DoctorSurname { get; set; } 
    public string DoctorGivenName { get; set; } 
} 

コントローラ

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); 
} 

ビュー

@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") 
} 

です210

答えて

1

問題を2日間見た後、問題を解決して5分後に解決策を見つけました!ドゥー!

私は二重ネガを混乱させていたようです。

私のコントローラでは、どこかでスイッチを切り替えるとtrueとfalseが得られ、期待通りに動作します。私は期待していなかった

ことの一つは、リモート検証は、フォーム上の送信ボタンを押すと、あなたが

  • 場を離れるときに二回

    1. 起動するようだということです。

    私は送信ボタンのチェックを期待していませんでした。

    うまくいけば、これは誰かを助けてくれるでしょう

  • 関連する問題