我有如下控制器的方法来获得数据,作为参数作为IEnumerable<samplemodel> model
“的IEnumerable <samplemodel>模式”值填入到另一个模型
[HttpGet]
public ActionResult Create_Template(IEnumerable<ProductsPropertiesVM> model)
{
return View(...);
}
这是ProductsPropertiesVM
模型类
public class ProductsPropertiesVM
{
public int Property_ID { get; set; }
public string Property_Title { get; set; }
public string Property_Value { get; set; }
public bool IsChecked { get; set; }
public string Product_Name { get; set; }
public string Product_Description { get; set; }
public string Prodcut_Features { get; set; }
public string Unique_Selling_Propositions { get; set; }
public string Business_Case_Feasibity_Study { get; set; }
public string Sharia_Resolution_and_Requirement_for_Product { get; set; }
public string Approved_Accounting_Entries { get; set; }
public string Listing_of_Risk_Related_Procedures { get; set; }
public string Legal_Requirement { get; set; }
public string Listing_of_Internal_Procedures_for_Review { get; set; }
public string Product_Statistics_Targeted_Segment { get; set; }
public string Product_Statistics_Sales_Volume { get; set; }
public string Product_Statistics_Profitability { get; set; }
public string Product_Statistics_Annual_Growth_Rate { get; set; }
public string Relevent_Case_Studies { get; set; }
}
到此控制器,数据像下面传递
图片1:10个元素[0-9索引]
图片二:
我想选择有限元素的属性这是本0-9索引的元素IsChecked
财产True
,并返回
分配该限制元素的属性我创建了另一个模型类如下
public class TemplateProperties
{
public int Property_ID { get; set; }
public string Property_Title { get; set; }
public string Property_Value { get; set; }
public bool IsChecked { get; set; }
}
于是我尝试做一些像下面
方法1:
[HttpGet]
public ActionResult Create_Template(IEnumerable<ProductsPropertiesVM> model)
{
IEnumerable<BrochureTemplateProperties> sample = model.Where(y => y.IsChecked).Select(y => new
{
sample.IsChecked = y.IsChecked,
sample.Name = y.Property_Title,
sample.PropertyValue = y.Property_Value
});
return View(sample);
};
但这收到编译错误
方法2:
[HttpGet]
public ActionResult Create_Template(IEnumerable<ProductsPropertiesVM> model)
{
var sample = model.Where(y => y.IsChecked).Select(y => new
{
IsChecked = y.IsChecked,
Name = y.Property_Title,
PropertyValue = y.Property_Value
});
return View(sample);
};
但这种做法一旦我转到视图模型值不能结合TemplateProperties模型,
我能做些什么,一旦我使用@Rahuls解决方案来解决这个
编辑
,几乎所有的编译错误走了,然后,我创建详细查看,但一旦我运行此得到一个错误页面这样
尝试用'你的LINQ查询.ToList()'后。 –
@StephenMuecke你说这个可怕的网址对我来说成了一个问题 – kez