具有继承性的模型的 asp.net mvc 默认模型绑定器

发布于 2024-10-10 10:36:52 字数 572 浏览 0 评论 0原文

我有一个绑定到的表单,其结构如下:

public class Status
{
   public List<ABCAttachment> ABCAttachments_Files { get; set; }
}

public class Attachment
{
  public string Id { get; set; }
}

public class ABCAttachment : Attachment
{
   string Name { get; set; }
}

我的操作如下所示:

public ActionResult SaveAttachment(Status status)
{
  ....
}

数据以表单形式传输

ABCAttachments_Files[0].Id="0", ABCAttachments_Files[0].Name="test" 

当我在 SaveAttachments 操作中访问状态时,ID 存在,但名称不存在。我看到它已正确发布,但为什么它没有正确绑定?

I have a form that I binding to that has the following structure:

public class Status
{
   public List<ABCAttachment> ABCAttachments_Files { get; set; }
}

public class Attachment
{
  public string Id { get; set; }
}

public class ABCAttachment : Attachment
{
   string Name { get; set; }
}

My action looks like this:

public ActionResult SaveAttachment(Status status)
{
  ....
}

The data is coming over in the form

ABCAttachments_Files[0].Id="0", ABCAttachments_Files[0].Name="test" 

When I access status in my SaveAttachments action the Id is there, but the Name is not. I see it correctly being posted, but why is it not binding properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅沫记忆 2024-10-17 10:36:52

看起来 Name 属性需要是公共的,否则它不会被限制为:

public class ABCAttachment : Attachment
{
   string Name { get; set; }
}

应该是

public class ABCAttachment : Attachment
{
   public string Name { get; set; }
}

Looks like the Name property needs to be public or it won't be bounded to:

public class ABCAttachment : Attachment
{
   string Name { get; set; }
}

should be

public class ABCAttachment : Attachment
{
   public string Name { get; set; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文