ASP.Net MVC 2 在自动生成强类型视图的视图内容时省略属性
这是一个简单的问题,但我在网上找不到答案。我有一个如下所示的类:
public class EquipmentItem : Item
{
public Status Status { get; set; }
public string Description { get; set; }
}
当我创建强类型视图并提供此类时,要求 ASP.Net MVC 自动创建一个用“创建”内容填充的视图,它会忽略 Status 类中的所有属性。有没有办法让我告诉 ASP.Net MVC 也为该类中的属性提供 HTML 输入字段?
谢谢
This is a simple question but I couldn't find an answer for it online. I have a class that looks like this:
public class EquipmentItem : Item
{
public Status Status { get; set; }
public string Description { get; set; }
}
When I create a strongly-typed view and provide this class, asking ASP.Net MVC to automatically make a view populated with "create" content it leaves out all of the properties in the Status class. Is there a way for me to tell ASP.Net MVC to also provide HTML input fields for the properties in that class?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你也可以做
you can also do
我总是将其视为当视图模型中具有此类属性时应该创建分部视图的标志。
无论如何,创建分部视图将允许您构建 Status 类的属性,因为它将强类型化为 status,而不是 EquipmentItem。
另一种方法是使用映射(例如,AutoMapper),并将域模型类映射到视图模型类。视图模型类将只具有 MVC 将为您搭建的简单属性。
I always take it as a sign that you should create a partial view when you have such properties in your view model.
In any case, creating the partial view will allow you to scaffold the properties of your Status class as it would be strongly typed to status, instead of EquipmentItem.
The alternative is to use mapping (eg, AutoMapper), and map your domain model class to your view model class. The view model class would just have simple properties that MVC will scaffold for you.