【发布时间】:2012-01-29 08:10:13
【问题描述】:
我在模型中有 2 个班级
public class User
{
public int UserID { get; set; }
public string UserName { get; set; }
}
public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
}
我有一个使用两个类的视图,我需要使用 html.TextBoxFor。 我可以创建 BigModel:
public class BigModel
{
public User user;
public Product product;
}
所以在视图中:
@model BigModel
@Html.TextBoxFor(m=> m.user.UserName)
@Html.TextBoxFor(m=> m.product.ProductName)
或者我可以使用不同的局部视图并重新读取它们。但它们不是我最喜欢的解决方案。
就没有别的办法了吗?如:
<p>
User Name:
@Html.TextBoxFor<User>(u=> u.UserName)
</p>
<p>
Product Name:
@Html.TextBoxFor<Product>(p=> p.ProductName)
</p>
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 razor html-helper