在我的ASP.NET MVC3应用程序中使用以下视图模型时,我遇到了下面描述的问题:
public class MyViewModel : ViewModelBase
{
  // having this line kills the one below it, while commenting it out solves the problem. WHY?
  [DataType(DataType.Text)]
  [Display(Name = "Name", Description = "Description", Prompt = "Prompt"]
  public new string MyField { get; set; }
}只要我注释掉[DataType(DataType.Text)],我就可以看到所有其他的东西都会出现,但是如果一起使用,DataType.Text在某种程度上会覆盖它下面的一个(至少看起来是这样)。
为什么会发生这种情况,以及如何解决?
提前谢谢。
发布于 2012-08-13 02:19:53
哦,我想通了。如果有人需要它:我在Shared/EditorTemplates/String.cshtml下有一个编辑器模板,它用DisplayAttribute完成了所有的魔术,而[DataType(DataType.Text)]实际上将字符串重定向为文本,我需要创建另一个与String.cshtl并行的EditorTemplate,称为Text.cshtml。
活到老,学到老!
https://stackoverflow.com/questions/11924558
复制相似问题