I am currently working on a small ecommerce project. I want to show a small description for a product instead of displaying all the description (comming from a database).
Here is my controller;
var products = context.Products.OrderBy(p => p.ProductName);
@ViewBag.ProductList = products.ToList<Product>();
And here is my view code;
<ul class="display" id="content">
@foreach( var item in @ViewBag.ProductList as IEnumerable<Product>)
{
@Html.Partial("_ProductPartial", item)
}
</ul>
Now inside my Partial “_ProductPartial” view, i have that description field called;
<p>
@Html.DisplayFor(model => model.ProductDescription)
</p>
Now, i want to display a short description for a product (instead of displaying the whole description which is by default works).
So, How can i do this using LINQ?
Is there any other way (if possible)?
I’m doing this by using ViewModel :
For you if you don’t want to make a ViewModel you could extend your Product class to have this read only property