Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

GridMVC

I want to add if qty >1 then qty / Price else just show price

how can I do this within the grid.

I cannot do it in the storedprocedure because the price is int not a string with my mvc project.

  @Html.Grid(Model).Named("Grid").Columns(columns => 
                    {
                            columns.Add(c => c.ItemDescription).Titled("Description").SetWidth(850);
                        columns.Add(c => c.ScanPrice).Titled("Price").Css("money").SetWidth(200).Direction.Equals("right");
                        columns.Add(c => c.BasePrice).Titled("qty").Css("money").SetWidth(200);
                         columns.Add(c => c.CreatedDate).Titled("Created Date").SetWidth(200).Format("{0:dd-MMM-yyyy}"); 
                                        }).WithPaging(10).Sortable(true)

Open in new window

Avatar of Mihai Stancescu
Mihai Stancescu
Flag of Romania image

Hi,

You can use a viewmodel or add a property on your model to reflect that behaviour and ignore it for the database if you're using codefirst.


Regards,
Mishu
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Seven price

ASKER

(x.Qty / x.Price).ToString()

Open in new window


this part is dividing  instead of using the slash as a empty string.
I thought you wanted to divide. If you just wanted to show a string literal then:

columns.Add().RenderValueAs(x => x.Qty == 1 ? "Price" : "Qty / Price").Titled("YourColumnName");

Open in new window


Giannis
I just convert / to "/" and it worked out. Thanks