2012-01-19 11 views
0

私はビューに対してクライアント側の検証を使用しており、組織オブジェクトとアドレスオブジェクトを含むViewModelを作成しました。ASP.NET MVC 3リモート検証が動作を停止しました

私は以前、ドメインエンティティにマップされたViewModelを持っていました。

[NotMapped] 
    [Remote("ValidOrganisation", "Manage", "Organisations", ErrorMessage = "That organisation doesn't exist")] 
    public string Organisation { get; set; } 

はしかし、私は今、以下を含むビュー用のViewModelを作成しました:

public class PersonModel 
{ 
    public Person Person { get; set; } 
    public AddressModel Address { get; set; } 
} 

人物オブジェクトが組織のプロパティが含まれている自分のドメインエンティティに私は次のようでした。私の見解では

は、私は次のようしている:

<div> 
      <label for="Organisation">Organisation</label> 
      <div class="input large"> 
       @Html.TextBoxFor(m => m.Person.Organisation) 
       <span class="help-block">Type the first letter of the organisation to search</span> 
       @Html.ValidationMessageFor(m => m.Person.Organisation) 
       @Html.Hidden("OrganisationID") 
      </div> 
     </div> 

た変更だけの事:

@Html.TextBoxFor(m => m.Organisation) 

へ:

@Html.TextBoxFor(m => m.Person.Organisation) 

私のリモート検証コードは次のとおりです。

public JsonResult ValidOrganisation(string organisation) 
    { 
     var exists = orgs.SelectAll().Where(o => o.Name.ToLower() == organisation.ToLower()).Count() > 0; 

     return Json(exists, JsonRequestBehavior.AllowGet); 
    } 

問題は、NULLが常に渡され、常にfalseを返すことです。

これは、組織プロパティがPerson.Organisationに変更されたことと関係していますか?

答えて

1

1]私は

Person_Organisation することを期待してい同じIDを受け入れるために、あなたのビューページのソースを開き、

@Html.TextBoxFor(m => m.Person.Organisation) 

2のID renderd]であるものを見ると、この方法で組織の名前を変更

public JsonResult ValidOrganisation(string Person_Organisation) 
以下
public JsonResult ValidOrganisation(string organisation) 

使用0

+0

私はそれを試みましたが、Person_Organisationは常にNULLです。 IDはPerson_Organisationで、名前はPerson.Organisationで、テキストボックスのinspect要素です。 – Paul

+0

FireBugを使用して、どのURLと値がサーバーに送信されたのか教えてください。 – swapneel

+0

アドバイスをいただきありがとうございますが、私は少しでもアプリケーションの再組み立てを行いました。私はまだあなたが上記で指定した方法を使用して動作することを拒否した理由を知りませんが。 – Paul

関連する問題