I am new to MVC3. I use WebGrid to display some of the columns on the site for the auction I'm working on. This displays a grid showing recent bids. When anyone other than the administrator logs in, they should only see the bid amounts and the date / time. When an administrator logs in, they should see all the columns (name and contact information). I think I will probably have to somehow massage this into the code, but I was wondering if there is a way to deal with it in Razor markup? Here I have it:
@{ 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, there is something like this in the pseudo code:
@{ 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? Do I need to code two different WebGrid and surround them with if (), maybe?
source share