전 제 질문을 검색했지만 couldnt 더 이상 얻을 수 있도록 아무것도 찾을 수 없습니다.ASP.NET MVC : 컨트롤러에 복잡한 뷰 모델 전달
현재 사용자에 대한 사용 권한을 설정할 수있는보기를 구현하려고합니다. 각 PermissionTree-Object가 하위 권한을 참조하는 경우 데이터 구조로
은 내가 (권한이 계층 적으로 내 응용 프로그램으로 구성되어 있습니다) 재귀 클래스에 따라 사용 을 : 여기public class PermissionTree
{
public Permission Node; //the permission object contains a field of type SqlHierarchyId if that is relevant
public bool HasPermission;
public IList<PermissionTree> Children;
//i cut out the constructors to keep it short ...
}
컨트롤러가 같은 모습입니다
@model PermissionTree
//....
@using (Html.BeginForm("Permissions", "Permission", null, FormMethod.Post, new { @class = "stdform stdform2" }))
{
<input name="save" title="save2" class="k-button" type="submit" />
<div class="treeview">
//i am using the telerik kendoUI treeview
@(Html.Kendo().TreeView()
.Name("Permissions")
.Animation(true)
.ExpandAll(true)
.Checkboxes(checkboxes => checkboxes
.CheckChildren(true)
)
.BindTo(Model, mapping => mapping
.For<PermissionTree>(binding => binding
.Children(c => c.Children)
.ItemDataBound((item, c) => {
item.Text = c.Node.PermissionName;
item.Checked = c.HasPermission;
})
)
)
)
:이 같은 강력한 형식의 뷰를 사용하여 오전에
//this is called to open the view
public ActionResult Permissions()
{
//pass the root element which contains all permission elements as children (recursion)
PermissionTree permissionTree = PopulateTree();//the fully populated permission-tree
return View(permissionTree);
}
//this is called when i submit the form
[HttpPost]
public ActionResult Permissions(PermissionTree model)
{
SetPermissions(model);
ViewData["PermissionsSaved"] = true;
return View(model);//return RedirectToAction("Index");
}
ok, 버튼을 클릭하면 [HttpPost]
으로 장식 된 컨트롤러 동작으로 내 viewmodel을 보내고 싶습니다. 하지만 응용 프로그램을 디버깅 할 때받은 모델에 실제로 내 데이터가 포함되어 있지 않습니다 (null이 아님). 누구나 내 목표를 달성하고 전체 viewmodel을 얻을 수있는 방법을 알고 있습니까?
안부, r3try이
보기에 입력 필드가 있습니까? – ken2k
아니요, 나는 체크 박스가있는 treeview 만 사용합니다. – r3try
모델 바인딩에서 어떤 일이 일어나는지보십시오. http : // stackoverflow.co.kr/questions/4651085/best-practices-for-debugging-asp-net-mvc-binding – ngm