I have following model classes
public class ProductViewModel
{
public Product Products { get; set; }
public IEnumerable<Product> LProducts { get; set; }
}
public partial class Product
{
public string id { get; set; }
public string detail { get; set; }
}
then I have following view for both List and Create
@model albaraka.Models.ProductViewModel
<table class="table">
<tr>
<th>
ID
</th>
<th>
Detail
</th>
</tr>
@foreach (var obj in Model.LProducts)
{
<tr>
<td>
@Html.DisplayFor(modelItem => obj.id)
</td>
<td>
@Html.DisplayFor(modelItem => obj.detail)
</td>
</tr>
}
</table>
<div>
@using ())
{
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.id)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Products.id)
@Html.ValidationMessageFor(m => m.Products.id)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Products.detail)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Products.detail)
@Html.ValidationMessageFor(m => m.Products.detail)
</div>
<p>
<input type="submit" value="Submit" />
</p>
</fieldset>
</div>
}
</div>
@section Scripts
{}
this is controller method for list
[HttpGet]
public ViewResult Product_List()
{
ProductViewModel viewModelList = new ProductViewModel();
viewModelList.LProducts = from products in db.Product
where products.details == "Pending"
select products;
return View(viewModelList.LProducts.ToList());
}
but here I'm getting following error
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[projectname.Models.Product]', but this dictionary requires a model item of type 'projectname.Models.ProductViewModel'.