Asp.net mvc 2 如何在ASP.NET MVC中处理嵌套模型

Asp.net mvc 2 如何在ASP.NET MVC中处理嵌套模型,asp.net-mvc-2,model-binding,Asp.net Mvc 2,Model Binding,我一直在寻找一个关于如何正确处理嵌套属性的模型绑定的很好的工作解决方案。我有一个模型,其中包含其他子模型的列表,如下所示: public class Organization : IEntity { [ScaffoldColumn(false)] public int ID { get; set; } [LocalizedDisplayName("Goals")] public virtual ICollecti

我一直在寻找一个关于如何正确处理嵌套属性的模型绑定的很好的工作解决方案。我有一个模型,其中包含其他子模型的列表,如下所示:

public class Organization : IEntity
{
    [ScaffoldColumn(false)]
    public int ID
    {
        get; 
        set;
    }

    [LocalizedDisplayName("Goals")]
    public virtual ICollection<OrganizationGoal> Goals
    {
        get;
        set;
    }
}
但是TryUpdateModel始终返回false,并且UI中不显示任何验证消息。用户界面是使用标准MVC助手编辑器for构建的

这样做的最佳实践是什么?对于一个非常正常的场景,要找到信息并不那么容易


谢谢

现在使用GetByIdentifier查询的是ID列吗?如果是这样,为什么要传入一个字符串,但在定义中将其作为int

另外,通过阅读关于TryUpdateModel的内容,听起来您可能想改用UpdateModel


Kristofer,你能提供一些关于通过FormCollection发布哪些键值对的详细信息吗?
[HttpPost]
public ActionResult Edit(string organizationIdentifier, FormCollection values)
{
    var organization = organizationService.GetByIdentifier(organizationIdentifier);

    if (TryUpdateModel(organization))
    {
       organizationService.Save(organization);
       return RedirectToAction("Edit");
    }

    return View("Edit");
}