Today i wanted to add a Details Link to my Grid.MVC Grid. The Problem is: It doesent want to get the id -> eg Model.ID can be listed, but in RenderValueAs, it is no member from x. I tried Model.id and modelitem.id... What am I doing wrong?
Many Thanks!
View:
@ModelType IEnumerable(Of WebApplication2.Datenbank.Dezernate)
@imports GridMVC.html
@Code
ViewData("Title") = "Index"
End Code
<html>
<head>
<title>Index</title>
<meta name="viewport" content="width=device-width" />
<link href="@Url.Content("~/Content/Gridmvc.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/bootstrap.min.css")" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/jquery-1.9.1.min.js")"></script>
<script src="@Url.Content("~/Scripts/gridmvc.min.js")"></script>
</head>
<body>
<div style="width:500px;">
@Html.Grid(Model).Columns(Function(modelitem)
'Erstellt das Grid für die anzeige der Geräte
modelitem.Add(Function(model) model.ID).Titled("ID")
modelitem.Add(Function(model) model.Dezernat).Titled("Dezernato")
modelitem.Add(Function(model) model.Rechner).Titled("Rechner").SetWidth(20)
modelitem.Add(Function(model) model.Scan).Titled("Scan").SetWidth(20)
modelitem.Add().Encoded(False).Sanitized(False).RenderValueAs(Html.ActionLink("Details", "Details", New With {.id = Model.id})) <-- Here is the unknown Member Model.id
End Function
).WithPaging(10).Sortable(True)
Model:
Namespace Controllers
Public Class HomeController
Inherits Controller
Private db As New TempDbContext
' GET: Home
Function Index(ByVal id As Integer?) As ActionResult
Dim db As New TempDbContext
ViewBag.DropdownDezernate = New SelectList(db.Dezernate1, "ID", "Rechner")
Return View(db.Dezernate1.ToList())
End Function
Function Details(ByVal id As Integer?) As ActionResult
If IsNothing(id) Then
Return New HttpStatusCodeResult(HttpStatusCode.BadRequest)
End If
Dim dezernate As Dezernate = db.Dezernate1.Find(id)
If IsNothing(dezernate) Then
Return HttpNotFound()
End If
Return View(dezernate)
End Function
Didn't find the doc for the VB version, but in C#,
RenderValueAs
takes aFunc<T, string>
parameter.So (sorry if my syntax is wrong, but I guess you'll get the idea)