Monday, January 5, 2015

Webgrid with Hidden PrimaryKey in ASP.Net MVC 4

It was very weird to know that we cannot have hidden column in webgrid.

Usually we keep Primary Key in hidden field/column in grids.

I successfully overcame this with the following logic.

The logic is :- Use the two fields [one label, one hidden] as HTML contols (one span, one hidden) in "grid.column"


grid.Column("RowNumber", format: item => rowNum = rowNum + 1),

grid.Column(null,header:"RoleName", style: "col4",
                 format:@<p>
                    <span>@item.RoleName</span>
                     <input type="hidden" id="DtoList[@(rowNum - 1)].RoleId" name="DtoList[@(rowNum - 1)].RoleId" value="@item.RoleId" />                    
                 </p>),



I couldn't find a way where we can combine  " RowNumber & Primary Key ".
That may be achievable, but I cannot spend time on that now.

It may help at least one another like me

happy coding..:-)

No comments:

Post a Comment