首先,我搜索了我的问题,但找不到任何可以帮助我更进一步的东西。
我正在尝试实现一个允许我为当前用户设置权限的视图。
作为数据结构,我使用以下递归类,其中每个 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 ...
}
这是控制器的样子:
//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");
}
我正在使用这样的强类型视图:
@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;
})
)
)
)
好的,所以当我单击按钮时,我希望将我的视图模型发送到用[HttpPost]
. 但是当我调试应用程序时,接收到的模型并没有真正包含我的数据(虽然它不是空的)。有谁知道我如何实现我的目标并获得整个视图模型?
最好的问候, r3try