簡體   English   中英

具有繼承關系的模型的asp.net mvc默認模型綁定程序

[英]asp.net mvc default model binder for model that has inheritance

我綁定到的表單具有以下結構:

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在那,但名稱不在。 我看到它正確地發布了,但是為什么綁定不正確?

看起來Name屬性需要是公共的,否則將不受限於:

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

應該

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM