ASP.NET Grid.MVC Html.Actionlink 不想工作
ASP.NET Grid.MVC Html.Actionlink wont want to work
今天我想在我的 Grid.MVC 网格中添加详细信息 Link。问题是:它不想获取 id -> 例如 Model.ID 可以列出,但在 RenderValueAs 中,它不是 x 的成员。我尝试了 Model.id 和 modelitem.id...
我做错了什么?
非常感谢!
查看:
@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)
型号:
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
未找到 VB 版本的文档,但在 C# 中,RenderValueAs
需要一个 Func<T, string>
参数。
所以(抱歉,如果我的语法有误,但我想你会明白的)
RenderValueAs(Function(model) Html.ActionLink("Details", "Details", New With {.id = model.id}))
今天我想在我的 Grid.MVC 网格中添加详细信息 Link。问题是:它不想获取 id -> 例如 Model.ID 可以列出,但在 RenderValueAs 中,它不是 x 的成员。我尝试了 Model.id 和 modelitem.id... 我做错了什么?
非常感谢!
查看:
@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)
型号:
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
未找到 VB 版本的文档,但在 C# 中,RenderValueAs
需要一个 Func<T, string>
参数。
所以(抱歉,如果我的语法有误,但我想你会明白的)
RenderValueAs(Function(model) Html.ActionLink("Details", "Details", New With {.id = model.id}))