asp.net-mvc – 传递IEnumerable变量以在ASP.NET MVC中查看
发布时间:2020-12-16 09:37:32 所属栏目:asp.Net 来源:网络整理
导读:我会说一点点英语.我试着问我的问题. 我有一个模特.它的名字是Product.cs Product { public int TypeId { get; set; }/*these are at the same time field of Type Table*/ public string TypeName { get; set; } public int TradeMarkId { get; set; }/*at
我会说一点点英语.我试着问我的问题.
我有一个模特.它的名字是Product.cs Product { public int TypeId { get; set; }/*these are at the same time field of Type Table*/ public string TypeName { get; set; } public int TradeMarkId { get; set; }/*at the same time field of TradeMark Table*/ public string TradeMarkName { get; set; } public int ProductId { get; set; }/*at the same time field of TProduct Table*/ public string ProductName { get; set; } public int TId { get; set; } public int TMId { get; set; } public List<TypeProduct> typeList { get; set; } } 我的控制器页面 My controller [HttpGet] public ActionResult TradeMarkProduckAdd() { Product product = new Product(); TypeList typeList = new TypeList(); product = typeList.TypeListOf(product); return View(product);//"This doesn't work" } 它说一个类型错误 当我收到此错误时,我更改了返回View(产品);至 查看页面 @using TypeTradeMark.Models @model IEnumerable<Product> @using (Html.BeginForm("AddProduct","Home",FormMethod.Post)) { @foreach(var item in Model as List<Product>) { @item.ProductName @item.??//checkbox for every record @item.??//dropdownlist for trademarks } } TypeList类 TypeList class public class TypeList { VtDataContext Vt = new VtDataContext(); public Product TypeListOf(Product typeListOf) { var query = (from c in Vt.Types select c); typeListOf.typeList=new List<Type>(query.ToList()); return typeListof; } } 我的桌子 Type : TypeId,TypeName TradeMark : TradeMarkId,TradeMarkName TProduct : ProductId,ProductName,TId,TMId//TId relation with TypeId,TMId relation with TradeMarkId 我无法解决问题你能帮助我吗?谢谢 解决方法
您可以查看产品类型对象的期望列表,请参阅(@model IEnumerable< Product>).
尝试使用这样的东西: return View(new List<Product> { product,product2 }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Response.Redirect()vs Response.RedirectPermanent()
- asp.net-mvc-3 – 如何使用ASP.NET MVC 3“Razor”查看引擎
- asp.net – MVC5发布到Azure,因为云服务在AD登录后重定向到
- asp.net-mvc – MVC索引页面和过滤器
- HttpClientFactory与Steeltoe结合来完成服务发现
- asp.net-mvc-4 – MVC 4创建slug类型url
- ASP.NET MVC – 更新预编译的Razor View文件直播生产
- asp.net – DotLess的“web”属性究竟做了什么?
- asp.net – 证明telerik报告的HtmlTextBox中的文本
- asp.net – 将linq查询结果转换为datatable C#
推荐文章
站长推荐
- 在.NET Core中使用简单的插件化机制
- asp.net-mvc – 添加MVC控件或视图时,Visual Stu
- asp.net – 在App_Code目录中调试长编译时间
- VS2017中使用组合项目_windows服务+winform管理_
- 数组 – ASP MVC控制器动作可以接收一个byte []吗
- asp.net-mvc – DisplayFormat未应用于十进制值
- ASP.NET Web API可以在与MVC相同的URL上工作吗?
- asp.net-mvc – 运行测试项目时自动启动ASP.MVC项
- asp.net-mvc – 异步处理asp.net mvc,提供客户端
- asp.net – SignalR(Hub)可以发送除信号制作者之
热点阅读