2012-06-21 2 views
0

컨테이너와 중첩 된 뷰 모델이 있고 중첩 된 뷰 모델을 렌더링하는 EditorFor를 사용하여 하나의 viewmodel (ConcreteViewModelA :: prop3)의 속성 중 하나에 대한 유효성 검사를 위해 remoteAttribute를 추가하려고합니다. 그러나 유효성 검사 컨트롤러 동작 메서드에서 얻을 수있는 모든 null입니다.접두사가있는 RemoteAttribute

Validate ([Bind (접두어 = "item")] string prop3)를 사용했지만 속성을 사용하려고했으나 여전히 NULL로 되돌아 왔습니다. 어떤 아이디어?

public class SomeContainer 
{ 
    public List<ISomethingViewModel> SomeViewModels { get; set; } 
} 

public class ConcreteViewmodelA : ISomethingViewModel 
{ 
    public int prop1 { get; set; } 
    public int prop2 { get; set; } 
    [Remote("Validate", "RemoteValidation")] 
    public string prop3 { get; set; } 
} 

public class ConcreteViewModelB : ISomethingViewModel 
{ 
    public int prop1 { get; set; } 
    public int prop2 { get; set; } 
} 

public interface ISomethingViewModel 
{ 
    int prop1 { get; set; } 
    int prop2 { get; set; } 
} 

보기 :

@model test.Models.SomeContainer 

@using (Html.BeginForm()) 
{ 
    @Html.ValidationSummary() 
    <p>Begin here</p> 
    foreach (var item in Model.SomeViewModels) 
    { 
     @Html.EditorFor(x => item) 
    }   
} 
+0

나는이 사용하는 작업을 얻을 수있었습니다을 읽을 같은 것을 할 수있는이 Validate?item.prop3=

처럼 보인다 Prefix = "item")] ConcreteViewmodelA vm3) – user965160

답변

2

는 뷰 모델을 정의하십시오 : 다음

public class MyViewModel 
{ 
    public string Prop3 { get; set; } 
} 

과 : 불을 지르고와

public ActionResult Validate([Bind(Prefix = "item")] MyViewModel model) 
{ 
    return Json(
     !string.IsNullOrEmpty(model.Prop3), 
     JsonRequestBehavior.AllowGet 
    ); 
} 
0

확인하시기 바랍니다. (공공 JsonResult 유효성 검사 ([바인딩 : 귀하의 URL 요청은 그래서 당신은 값

public ActionResult Validate(string prop3) 
    { 
     string prop3Val = Request.QueryString["item.prop3"].ToString(); 

     //your operations with prop3Val 
     return Json(prop3Val, JsonRequestBehavior.AllowGet); 
    } 

enter image description here

+0

예, 방화 광구가 URL을 다음과 같이 표시합니다 : [link] 확인 하시겠습니까? item.prop3 = hello – user965160

관련 문제