MVC3 WebGrid - Row Id
How can you specify the row id or class with a specific id?
<tr id="row1">
Or even this is ok
<tr class="row1">
I was thinking something like this would work but it doesn't.
@grid.GetHtml(
rowStyle: "row_" + grid.Column(columnName: "Id")
Anyone have any idea how i can possibly use the htmlAttributes or something t开发者_如何学运维o get this?
If i was using the for loop then thats easy but the WebGrid allows me to sort and page.
@foreach (var item in Model)
{
var rowid = "row" + @item.Id;
<tr id="@rowid">
checkout this post: http://haacked.com/archive/2011/04/14/a-better-razor-foreach-loop.aspx eventhough the demonstration is done using FOREACH loop it is very easy to imagine this solution with regular grid control "bound" to model. the thing is that you will calculate this ID as the very last operation before you send the model to view so it works also for sorted grid (so first row has ID = 1). btw. i really dont get it why this is not supported by grid directly. it is problem also in MVC Contrib grid (ok, this is OSS project so instead of bitching i should implement it :) ). i found such IDs inevitable when you want to make the grid editable because of the way ASP.NET MVC 3 model binder works.
精彩评论