ASP.NET Grid.MVC Html.Actionlink不想工作

时间:2017-05-18 06:55:43

标签: asp.net asp.net-mvc asp.net-mvc-4 razor grid.mvc

今天我想在Grid.MVC Grid中添加一个Details链接。问题是:它想要获得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

1 个答案:

答案 0 :(得分:0)

未找到VB版本的文档,但在C#中,RenderValueAs采用Func<T, string>参数。

所以(对不起,如果我的语法错误,但我想你会得到这个想法)

RenderValueAs(Function(model) Html.ActionLink("Details", "Details", New With {.id = model.id}))