MVC4의 드롭 다운 목록을 사용하여 편집기 템플릿을 만들려고합니다. 나는 dropdownlistfor 같은 뷰에서 직접 작업을 얻을 수 있습니다 :Html.DropDownListFor를 EditorTemplate으로 이동
@Html.DropDownListFor(model => model.Item.OwnerId, new SelectList(Model.DDLOptions.CustomerOptions, "Value", "DisplayText"))
그러나 그것을 "generify"및 에디터 템플릿에 그것을 넣어, 나는 그것이 동작하지 않습니다.
@Html.DropDownListFor(model => model, new SelectList(Model.DDLOptions.CustomerOptions, "Value", "DisplayText"))
나는 오류가 점점 오전 :
public class DDLOptions<T>
{
public T Value { get; set; }
public string DisplayText { get; set; }
}
이 작업을 수행합니다
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'int' does not contain a definition for 'DDLOptions'
Model.DDLOptions.CustomerOptions
유형 IEnumerable<DDLOptions<int>>
이다를 여기
@Html.DropDownListFor(model => model, new SelectList(Model.DDLOptions.CustomerOptions, "Value", "DisplayText"))
단순히 위의 코드를 기반 INT,하지만 그때 너무 부분에서 new SelectList(Model.DDLOptions.CustomerOptions, "Value", "DisplayText")
를 호출하고 귀하의 모델을 참조 Model.DDLOptions하지 않습니다 :
감사합니다. 당신이 그것을 전달하지 않으면 편집기 템플릿은 전체 뷰 모델을 인식하지 못합니다. @ Html.EditorFor (model => model.Item.Attribute1, new {Options = Model.DDLOptions.ItemAttributeOptions.Attribute1Options}) 편집기에 전달하는 방법은 다음과 같습니다. 여기에 데이터를 읽으려는 편집기가 있습니다. @Html.DropDownListFor (model => model, new SelectList (IEnumerable>) ViewData [ "Options"] "Value", "DisplayText", Model)) –