I wish to build a partial view that gets a model column and print it. Something like that:
At the view:
@model IEnumerable<products_comparison.Models.Product>
@{
ViewBag.Title = "Index";
var Brand = (from r in Model
select r.Brand).Distinct();
}
<h2>
Index</h2>
@Html.RenderPartial("_DisplayAttribute",Brand)
And at the partial view:
<table>
<tr>
<th>
Brand
</th>
</tr>
@foreach (var row in Model)
{
<tr>
<td>
@Html.DisplayFor(r => row)
</td>
</tr>
}
</table>
There are a few problems I run into:
- The compiler doesnt allow me to send Barnd to the partial view.
- If you look at the partial view code you will see the word Brand, which is the column name. I dont wish to hard-coded the word "Brand" in the partial view, instead I like that the column name will be there.
- In the partial view I need to put @model products_comparison.Models.Product, but I dont want to send the hole table. I want to send only one column - But I dont know what to put there..
Thanks!
EDIT:
Just to clear one thing, I want that the view will call the same partial view for each column in the table(for most of the columns in the table anyway) and each time I'll send a different column(distinct value column to be exact).