Asp.net mvc 4 提交后模型属性为空

Asp.net mvc 4 提交后模型属性为空,asp.net-mvc-4,Asp.net Mvc 4,我有这个模型: public partial class Group { public Group() { this.ParameterGroup = new HashSet<ParameterGroup>(); } public string GroupId { get; set; } public string Responsibility { get; set;

我有这个模型:

 public partial class Group
    {
        public Group()
        {
            this.ParameterGroup = new HashSet<ParameterGroup>();
        }

        public string GroupId { get; set; }
        public string Responsibility { get; set; }

        public virtual Text GroupDescText { get; set; }
        public virtual Text GroupNameText { get; set; }
        public virtual ICollection<ParameterGroup> ParameterGroup { get; set; }
    }

public partial class Text
    {
        public Text()
        {
            this.ParamName = new HashSet<Parameter>();
            this.ParamDesc = new HashSet<Parameter>();
            this.EnumElemName = new HashSet<EnumElem>();
            this.IoDeviceInfoText = new HashSet<IoDeviceInfo>();
            this.IoCatText = new HashSet<IoDeviceInfo>();
            this.GroupDesc = new HashSet<Group>();
            this.GroupName = new HashSet<Group>();
            this.Type = new HashSet<Type>();
            this.ParamDispPath = new HashSet<Parameter>();
            this.EnumElemText = new HashSet<EnumElem>();
            this.TextValue = new HashSet<TextValue>();
        }

        public string TextId { get; set; }
        public string XmlId { get; set; }

        public virtual ICollection<Parameter> ParamName { get; set; }
        public virtual ICollection<Parameter> ParamDesc { get; set; }
        public virtual ICollection<EnumElem> EnumElemName { get; set; }
        public virtual ICollection<IoDeviceInfo> IoDeviceInfoText { get; set; }
        public virtual ICollection<IoDeviceInfo> IoCatText { get; set; }
        public virtual ICollection<Group> GroupDesc { get; set; }
        public virtual ICollection<Group> GroupName { get; set; }
        public virtual ICollection<Type> Type { get; set; }
        public virtual ICollection<Parameter> ParamDispPath { get; set; }
        public virtual ICollection<EnumElem> EnumElemText { get; set; }
        public virtual ICollection<TextValue> TextValue { get; set; }
    }
公共部分类组
{
公共组()
{
this.ParameterGroup=new HashSet();
}
公共字符串GroupId{get;set;}
公共字符串责任{get;set;}
公共虚拟文本组desctext{get;set;}
公共虚拟文本GroupNameText{get;set;}
公共虚拟ICollection参数组{get;set;}
}
公共部分类文本
{
公共文本()
{
this.ParamName=new HashSet();
this.ParamDesc=新的HashSet();
this.EnumElemName=新HashSet();
this.iodeviceinfo=new HashSet();
this.IoCatText=new HashSet();
this.GroupDesc=新的HashSet();
this.GroupName=new HashSet();
this.Type=new HashSet();
this.ParamDispPath=new HashSet();
this.EnumElemText=new HashSet();
this.TextValue=new HashSet();
}
公共字符串TextId{get;set;}
公共字符串XmlId{get;set;}
公共虚拟ICollection参数名{get;set;}
公共虚拟ICollection ParamDesc{get;set;}
公共虚拟ICollection EnumElemName{get;set;}
公共虚拟ICollection IODeviceInfo文本{get;set;}
公共虚拟ICollection IoCatText{get;set;}
公共虚拟ICollection GroupDesc{get;set;}
公共虚拟ICollection组名{get;set;}
公共虚拟ICollection类型{get;set;}
公共虚拟ICollection ParamDispPath{get;set;}
公共虚拟ICollection EnumElemText{get;set;}
公共虚拟ICollection TextValue{get;set;}
}
这是我的控制器:

 public class GroupController : Controller
    {
        // GET: Group
        public ActionResult Index()
        {
            return PartialView("Index", GroupModel.Instance.getGroups());
        }

        public ActionResult Edit(string id)
        {
            Group group = KebaContext.SessionBasedContext().GroupSet.Where(g => g.GroupId == id).FirstOrDefault();
            List<Language> langs = KebaContext.SessionBasedContext().LanguageSet.ToList();
            foreach(Language l in langs)
            {
                if(group.GroupDescText == null)
                {
                    group.GroupDescText = new Text();
                    TextValue value = new TextValue();
                    value.TextId = Guid.NewGuid().ToString("N");
                    value.LangId = l.LangId;
                    value.Value = "";
                    group.GroupDescText.TextValue.Add(value);
                }
                if (group.GroupNameText == null)
                {
                    group.GroupNameText = new Text();
                    TextValue value = new TextValue();
                    value.TextId = Guid.NewGuid().ToString("N");
                    value.LangId = l.LangId;
                    value.Value = "";
                    group.GroupNameText.TextValue.Add(value);
                }
                if (group.GroupDescText != null && group.GroupDescText.TextValue.Where(x => x.LangId == l.LangId).FirstOrDefault() == null) //just one lang is available
                {
                    TextValue value = new TextValue();
                    value.TextId = group.GroupDescText.TextValue.First().TextId;
                    value.LangId = l.LangId;
                    value.Value = "";
                    group.GroupDescText.TextValue.Add(value);
                }
                if (group.GroupNameText != null && group.GroupNameText.TextValue.Where(x => x.LangId == l.LangId).FirstOrDefault() == null) //just one lang is available
                {
                    TextValue value = new TextValue();
                    value.TextId = group.GroupNameText.TextValue.First().TextId;
                    value.LangId = l.LangId;
                    value.Value = "";
                    group.GroupNameText.TextValue.Add(value);
                }
            }
            return View(group);
        }

        [HttpPost]
        public ActionResult Edit(Group xyz)
        {

            return RedirectToAction("Index", "Types");
        }
    }
公共类GroupController:Controller
{
//获取:组
公共行动结果索引()
{
返回PartialView(“Index”,GroupModel.Instance.getGroups());
}
公共操作结果编辑(字符串id)
{
groupgroup=KebaContext.SessionBasedContext().GroupSet.Where(g=>g.GroupId==id).FirstOrDefault();
List langs=KebaContext.SessionBasedContext().LanguageSet.ToList();
foreach(语言l,以langs表示)
{
if(group.GroupDescText==null)
{
group.GroupDescText=新文本();
TextValue=新的TextValue();
value.TextId=Guid.NewGuid().ToString(“N”);
value.LangId=l.LangId;
value.value=“”;
group.GroupDescText.TextValue.Add(值);
}
if(group.GroupNameText==null)
{
group.GroupNameText=新文本();
TextValue=新的TextValue();
value.TextId=Guid.NewGuid().ToString(“N”);
value.LangId=l.LangId;
value.value=“”;
group.GroupNameText.TextValue.Add(值);
}
if(group.GroupDescText!=null&&group.GroupDescText.TextValue.Where(x=>x.LangId==l.LangId).FirstOrDefault()==null)//只有一个lang可用
{
TextValue=新的TextValue();
value.TextId=group.GroupDescText.TextValue.First().TextId;
value.LangId=l.LangId;
value.value=“”;
group.GroupDescText.TextValue.Add(值);
}
if(group.GroupNameText!=null&&group.GroupNameText.TextValue.Where(x=>x.LangId==l.LangId).FirstOrDefault()==null)//只有一个lang可用
{
TextValue=新的TextValue();
value.TextId=group.GroupNameText.TextValue.First().TextId;
value.LangId=l.LangId;
value.value=“”;
group.GroupNameText.TextValue.Add(值);
}
}
返回视图(组);
}
[HttpPost]
公共操作结果编辑(组xyz)
{
返回重定向操作(“索引”、“类型”);
}
}
我的看法是:

@using System.Web.Mvc.Html;
@model Keba.Data.EF.Group
@{
    ViewBag.Title = "Group Editing";
}
<h2>Edit Group</h2>
<div id="groupEdit">
    @using (Html.BeginForm("Edit", "Group", FormMethod.Post))
    {
        @Html.HiddenFor(model => model.GroupId);
        <table class="userEditAddTable">
            <tr><th>Responsibility</th><td>@Html.EditorFor(model => model.Responsibility)</td></tr>
            @foreach (var name in Model.GroupNameText.TextValue)
            {
                @Html.HiddenFor(model => name.LangId)
                @Html.HiddenFor(model => name.Value)
                <tr><th>GroupNameText(@Html.DisplayFor(model => name.LangId))</th><td> @Html.TextBoxFor(model => name.Value)</td></tr>;
            }
            @foreach (var desc in Model.GroupDescText.TextValue)
            {
                @Html.HiddenFor(model => desc.LangId)
                @Html.HiddenFor(model => desc.Value)
                <tr><th>GroupDescText(@Html.DisplayFor(model => desc.LangId))</th><td> @Html.TextBoxFor(model => desc.Value)</td></tr>;
            }
        </table>
        <br />
        <div id="buttons">
            <input name="Save" type="submit" value="Save" class="button" />
            <input name="Cancel" type="submit" value="Cancel" class="button" />
        </div>
    }
</div>
@使用System.Web.Mvc.Html;
@模型Keba.Data.EF.Group
@{
ViewBag.Title=“组编辑”;
}
编辑组
@使用(Html.BeginForm(“编辑”、“分组”、FormMethod.Post))
{
@Html.HiddenFor(model=>model.GroupId);
Responsibility@Html.EditorFor(模型=>model.Responsibility)
@foreach(Model.GroupNameText.TextValue中的变量名)
{
@Html.HiddenFor(model=>name.LangId)
@Html.HiddenFor(model=>name.Value)
GroupNameText(@Html.DisplayFor(model=>name.LangId))@Html.TextBoxFor(model=>name.Value);
}
@foreach(Model.GroupDescText.TextValue中的变量desc)
{
@Html.HiddenFor(model=>desc.LangId)
@Html.HiddenFor(model=>desc.Value)
GroupDescText(@Html.DisplayFor(model=>desc.LangId))@Html.TextBoxFor(model=>desc.Value);
}

}
问题:

如果我试图更改组模型中文本的值,例如GroupNameText.TextValue.value,请将其发送给控制器(提交)。属性GroupNameText和GroupDescText为空。
我还尝试了propertybinding(
[Bind(Include=“GroupDescText,GroupNameText”)]Group xyz)的解决方案,但它也不起作用。首先,请记住,只有发布的属性(即具有表示它们的表单输入元素)才会被填充

其次,输入元素的名称必须与模型绑定器在post上所期望的内容相匹配,否则它将丢弃这些值,因为它不会
@for (var i = 0; i < Model.GroupNameText.TextValue; i++)
{
    @Html.HiddenFor(m => m.GroupNameText.TextValue[i].LangId)
    @Html.HiddenFor(m => m.GroupNameText.TextValue[i].Value)
    ...
}