I am new to MVC3 - I am using a WebGrid to display some columns on a site for an auction I'm working on. This displays a grid showing the latest bids. When anyone except an admin logs in, they should only see the bid amounts and date/time. When an admin logs in, they should see all the columns (name and contact info). I'm thinking I will probably have to massage this in code behind somehow, but I was wondering if there is a way to handle it in Razor markup? Here is the I have now:
@{ var grid = new WebGrid(Model.Bids.OrderByDescending(b => b.BidAmount)); }
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("BidAmount", format: @<text>$@item.BidAmount</text>),
grid.Column("BidDateTime"),
grid.Column("FirstName"),
grid.Column("LastName"),
grid.Column("Email"),
grid.Column("PhoneNumber")
)
)
So what I want to do, in pseudo code, is something like this:
@{ var grid = new WebGrid(Model.Bids.OrderByDescending(b => b.BidAmount)); }
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("BidAmount", format: @<text>$@item.BidAmount</text>),
grid.Column("BidDateTime"),
@if(userIsAdmin){
grid.Column("FirstName"),
grid.Column("LastName"),
grid.Column("Email"),
grid.Column("PhoneNumber")
)
}
)
Can this be done? If not, any ideas on how to approach it? Would I need to code two different WebGrid's, and surround them with an if() maybe?