【问题标题】:Model binding problem模型绑定问题
【发布时间】:2011-07-06 09:03:45
【问题描述】:

我有这个代码

public class Room
{
    public string Id { get; set; }
    public List<person> people { get; set;}        
}
}

public class person
{
    public int Id { get; set; }
    public string Name { get; set; }
}

我正在尝试绑定人员列表并将其放置在房间对象中

我为人名创建我的文本框,并将它们命名为 people[index].Name 我可以将它们绑定到人员列表(通过删除人员),但我不能将它们绑定到 Rooms 人员对象。有什么办法吗?

【问题讨论】:

  • 向我们展示您的观点。你应该使用EditorFor。你是吗?

标签: asp.net-mvc asp.net-mvc-3


【解决方案1】:
public ActionResult([Bind(Prefix="people")]person p)

【讨论】:

  • 并将 person 更改为 Person,因为它是一个类名
【解决方案2】:

你好,我找到答案了

在 mvc 2 中你需要一个索引,而在 3 中你不需要(wrt Non-Sequential Indices)。 This 网站提供了一些见解

很抱歉,我从来没有给你们足够的信息来回答这个问题。我使用多种解决方案,现在很难跟踪。

感谢您的回复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-22
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多