In my Razor view, I have this webgrid:
@{
var grid = new WebGrid(Model, canPage: false, selectionFieldName: "VendorClassID", canSort:false);
}
@grid.GetHtml(
headerStyle: "header",
htmlAttributes: new{id = "tableGrid"},
tableStyle: "webgrid",
selectedRowStyle: "webgrid-selected-row",
columns: grid.Columns(
grid.Column(header: "Select", format: @<text>@item.GetSelectLink("Select")</text>),
grid.Column("ClassID", "ID"),
grid.Column("ClassNum", "Class Num"),
grid.Column("Description")
)
)
@if (grid.HasSelection)
{
var x = @grid.SelectedRow;
}
It's my understanding that when I click the generated "select" link, the page posts back and the URL gets a parameter "VendorClassID = selectrowindex" added on. However, the value of the parameter seems to be the index of the selected row, which isn't particularly useful to me. Is there anyway to have the parameter value be set to a value from the selected row (ClassID, etc)? The @grid.SelectedRow doesn't seem to know anything about the row's data either, but I am new to MVC so perhaps there is a way to get the row data from there?
I found the solution, I got the data I wanted (VendorClassID), by using
@if (grid.HasSelection)
{
var x = grid.SelectedRow.Value.VendorClassID;
//logic
}
VendorClassID is an attribute of my VendorClass. The page has a list of VendorClasses for its Model