【问题标题】:MVCContrib Grid Razor problem, Column.Action do not renderMVCContrib Grid Razor 问题,Column.Action 不渲染
【发布时间】:2011-01-20 17:15:26
【问题描述】:

下面的代码适用于 aspx 视图引擎,我正在尝试将其转换为 razor,如下所示。问题是第一列不显示。

我使用操作方法将第一列转换为链接。使用剃刀它(第一列)根本不会在页面中呈现。网格的其余部分都很好。

可能是什么问题?

@{Html.Grid(Model.Orders).Attributes(style => "width: 100%;").Columns(
column => {
    column.For(x => x.OrderNumber).Action(p => {
        @:<td>
        Html.ActionLink(
            p.OrderNumber.ToString(),
            "orderdetail",
            "OrderUpdate",
            new { id = p.OrderNumber, backUrl = Url.Action("OrderHistory", new { controller = "DataController", id = ViewData["id"] }) },
            new { });
        @:</td>
    }).HeaderAttributes(style => "text-align:left");

    column.For(x => x.OrderTimeV2).HeaderAttributes(style => "text-align:left");

    column.For(x => x.Status).HeaderAttributes(style => "text-align:left");

    column.For(x => x.Type).HeaderAttributes(style => "text-align:left");
}).RowStart((p, row) => { }).Render();}

【问题讨论】:

  • 你找到解决办法了吗?
  • 嗨,Daveo,我刚刚回答了我自己的问题

标签: razor mvccontrib mvccontrib-grid


【解决方案1】:

我已经不再使用 mvccontrib 网格,因为它在我们拥有的网格中没有多大意义。

无论如何,问题是问题中的代码不返回 html,而是将代码直接放入响应流中。以及使用 razor 呈现的列的代码,该代码在调用时将其放入流中。所以它最终会在渲染网格之前将列放入流中。

通过不使用网格调用的剃须刀代码来解决此问题。

【讨论】:

    【解决方案2】:

    好的,我通过以下方式为我工作

     @Html.Grid(Model.Result).Columns(column => {
        column.For(u => u.Name).Named("Name");
        column.For(u => u.Code).Named("Code");
        column.For(u => Html.ActionLink("Edit", "Edit", new { id = u.Id })).Named("Edit");
    

    【讨论】:

      【解决方案3】:

      你可以做一个自定义列来得到你想要的:

      @Html.Grid(Model).Columns(column => {
        column.Custom(
          @<div>
            <em>Hello there</em>
            <strong>@item.Name</strong>
          </div>
         ).Named("Custom Column");
      })
      

      发件人:MvcContrib Grid Custom Columns (Razor)

      我在将一些 .aspx 页面移植到 Razor 时这样做了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-13
        • 1970-01-01
        • 1970-01-01
        • 2011-04-25
        • 1970-01-01
        • 2013-11-26
        • 2019-04-28
        相关资源
        最近更新 更多