如何使用模型绑定器绑定复杂数据类型

时间:2013-11-22 10:07:56

标签: asp.net-mvc asp.net-mvc-4 model-binding

我有以下View Model类: -

public class VirtualMachineOnIT360Only
    {
        public TMSVirtualMachine VirtualMachine { get; set; }
        public IPagedList<Resource> Resources { get; set; }

    }

我使用模型类的部分视图如下所示: -

@foreach (var item in Model.Resources) {
@using (Ajax.BeginForm("CreateOnTMS","VirtualMachine", new AjaxOptions {
 InsertionMode = InsertionMode.Replace,
 UpdateTargetId = item.RESOURCEID.ToString() ,
 //LoadingElementId = item.RESOURCEID.ToString(),
 HttpMethod = "POST"})){
@Html.AntiForgeryToken()
   <span class="f">VM Role</span>
//code goes here
@Html.HiddenFor(modelitem=>item.RESOURCEID)
    @Html.HiddenFor(modelitem=>item.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization.NAME)
@Html.HiddenFor(modelitem=>item.ResourceLocation.SiteDefinition.SDOrganization.NAME)
@Html.HiddenFor(modelitem=>item.RESOURCENAME)
 <input type="submit" value="Add To TMS" class="btn btn-primary"/>

我面临的问题是我无法绑定Hiddenfor字段,当我检查页面源时,这些隐藏的字段名称将是工作项的前缀,如: -

item.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization.NAME.

那么在我的post action方法中如何绑定这些hiddenfor字段?

0 个答案:

没有答案