问题
After a bit of a struggle I've managed to bind my model to a Kendo Grid in my MVC app. What I want to do now is add either a Html.ActionLink or a button at the end of each row so that when clicked it opens a new browser window with the details page for the selected person.
My Grid code is such:
@ModelType CDB.GridDetail
@Code
Dim myGridData As IQueryable(Of Person) = Model.GridDetailPersons
Html.Kendo().Grid(Of Person)(myGridData) _
.Name("Grid") _
.Columns(Sub(c)
c.Bound(Function(s) s.PersonID)
c.Bound(Function(s) s.Status)
c.Bound(Function(s) s.OperationsTeam)
c.Template(Sub()
Html.ActionLink("View", "Details", New With {.id = "PersonID"}, New With {.target = "_blank"})
End Sub).Title("View").ClientTemplate("client template")
End Sub) _
.Scrollable() _
.Render()
End Code
The issue I am having is that I can't find a way to bind the PersonID for the row to the .id of the ActionLink. I have tried Person.PersonID and myGridData.PersonID
The code as it is renders the grid and data but no links... the column is empty.
Any help appreciated.
回答1:
The column template is a template, it is processed with Kendo's JS templating language and then used for each displayed row. Ie. you need to write code write a Kendo JS template than will be used to create the content that the browser will render.
In this case, because Html.ActionLink
doen't validate route parameters is to put the template into the id parameter:
Html.ActionLink("View", "Details", New With {.id = "#:PersonId#"}, New With {.target = "_blank"}
See Kendo's templates online.
回答2:
Tried Richard's answer but this did not work... returned syntax error.
Following the link he provided and looking at some of the other documentation I did find this which did work...
c.Bound(Function(p) p.PersonID).Template(Function(t) @<text>@Html.ActionLink("View", "Details", New With {.id = t.PersonID}, New With {.target = "_blank"})</text>
End Function).Title("View Details").HtmlAttributes(New With {.style = "text-align:center;"})
which I used to replace the c.Template(Sub..... line
来源:https://stackoverflow.com/questions/34062506/adding-view-or-button-link-to-kendo-grid