면도기 및 MVC3을 사용하여 ViewModel을 렌더링하려고합니다. 어떤 이유에서든 내 SelectList (아래 WidgetTypes)는 나머지는 모두 정상적으로 렌더링되지만 렌더링하지 않습니다. 누군가가 왜 빛을 비추 줄 수 있습니까? 같은 문제가 발생할 위젯에 대한 동적 모델을 사용하기 때문에 각 필드에 대해 @ Html.EditorFor (m => m.SystemName) 등을 사용하도록보기를 변경하고 싶지 않습니다.@ Html.EditorFor를 사용할 때 MVC3이 SelectList를 렌더링하지 않습니다
내 뷰 모델 :
public class CreateWidgetViewModel
{
[Required]
public string Title { get; set; }
[Required(ErrorMessage = "The System Name is required")]
[Display(Name = "System Name")]
public string SystemName { get; set; }
[Required]
[Display(Name = "Widget Type")]
public string WidgetType { get; set; }
[Required]
[Display(Name = "Widget Types")]
public SelectList WidgetTypes { get; set; }
}
내 컨트롤러 :
[HttpGet]
public ActionResult Create()
{
var widgetTypes = from wt in _widgetService.WidgetTypes
select new
{
Name = wt.WidgetName,
WidgetType = wt.GetType().AssemblyQualifiedName
};
var viewModel = new CreateWidgetViewModel
{
WidgetTypes = new SelectList(widgetTypes, "WidgetType", "Name")
};
if (Request.IsAjaxRequest())
{
return PartialView(viewModel);
}
return View(viewModel);
}
내보기 : 당신은 당신이 드롭 다운 목록을 생성 할 경우 Html.DropdownListFor
도우미를 사용할 필요가
@{
ViewBag.CurrentPage = "widgets";
}
<h2>@ViewBag.Title</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<div>
@Html.EditorFor(model => model)
</div>
</fieldset>
<div>
<input type="submit" value="Save" /> or @Ajax.ActionLink("Back to list", "Index", "Widget",
new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "ajax-replace" })
</div>
}
모델에서 SelectList를 사용하면 직렬화 할 수 없으므로 좋지 않습니다. 상태 서버를 켜면 토스트가됩니다. – gangelo