我希望我解释正确.. 我想要做的是建立一个会议阵列与产品列表中。 然后显示这些文本中的窗体分位旁边的分栏,并能够提交它们。我想我需要使用模板编辑器。但我不知道如何将数据放入项目列表中。MVC模板编辑器如何显示来自两个模型的项目
这是怎么了,目前正在填充我的会话变量..
IList<EnqProduct> items2 = Session["enquiry"] as IList<EnqProduct>;
desc = desc.Replace(",", "");
EnqProduct item = new EnqProduct();
item.Id = (items2.Count + 1).ToString();
item.Product = desc;
item.Quantity = "0";
items2.Add(item);
所以递减,可以productone,产品分类二等等
询问产品型号:
namespace MvcEditorTemplates.Models
{
public class EnqProduct
{
public string Id { get; set; }
public string Product { get; set; }
public string Quantity { get; set; }
}
}
正常询价型号:
public class Enquiry
{
public List<EnqProduct> EnqProduct { get; set; }
}
我如何试图填充模型,但这是静态的。我需要从数组项填充:
var EnquiryModel = new Enquiry {
EnqProduct = items2.Select(c => new EnqProduct()
{
Quantity = c.Quantity,
Product = c.Product
})
};
询问产品模板视图:
@model MvcEditorTemplates.Models.EnqProduct
<div class="fl">
<p>
@Html.LabelFor(x => x.Product)
@Html.TextBoxFor(x => x.Product)
</p>
<p>
@Html.LabelFor(x => x.Quantity)
@Html.TextBoxFor(x => x.Quantity)
</p>
</div>
这是怎么即时试图让它显示喧嚣的观点:
@Html.EditorFor(model => model.EnqProduct)
编辑:
在items2.Select(c => new EnqProduct()
我得到一个IEnumerbale错误一些关于转换?
如果要显示来自两个模型的数据,只需创建具有两个属性的组合ViewModel;每个型号一个。 –
我需要将它提交回aswel,并且产品列表是动态的 – Beginner