2016-04-15 13 views
0

リモートバリデータを使用していますが、デバッガがそのメソッドをトレースしていなくても動作しません。mvcでリモート検証が機能していません。

 public JsonResult CheckStrategyName(string StrategyName) 
     { 
      var ab = from a in db.Sterategy where a.StrategyName == StrategyName select a.StrategyName; 

      return !ab.Any() ? Json(true, JsonRequestBehavior.AllowGet) : Json(string.Format("Name Already esists"), JsonRequestBehavior.AllowGet); 
     } 

私はここで、私は間違いを犯してい

 [Required] 
     [Remote("CheckStrategyName", "St", ErrorMessage = "Already exists ")]  
     [Display(Name = "Name")] 
     public string StrategyName { get; set; } 

のWebConfig

<appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 

をそれを使用していますか? :(

答えて

1

お使いのサーバーのコード&設定は、罰金のようです。以下を確認してくださいあなたは、関連する入力フィールドのマークアップを生成するためにTextBoxForヘルパーメソッドを使用しており、それが内部にある場所

  1. でありますフォーム。

    @using (Html.BeginForm()) 
    {  
        @Html.TextBoxFor(s => s.StrategyName) 
        @Html.ValidationMessageFor(s => s.StrategyName)  
    
        <input type="submit" value="Submit" /> 
    } 
    
  2. あなたは、検証のために必要なJavaScriptのライブラリが含まれている。

    <script src="~/Scripts/jquery.js"></script> 
    <script src="~/Scripts/jquery.validate.js"></script> 
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script> 
    
+0

これらのライブラリは含まれませんでした。今はうまくいきます、ありがとうございます。 – Nil