开发者

MVCContrib Grid Razor problem, Column.Action do not render

开发者 https://www.devze.com 2023-02-05 14:19 出处:网络
Code below works great with aspx view engine, i am trying to convert it to razor as below. Problem is first column do not show up.

Code below works great with aspx view engine, i am trying to convert it to razor as below. Problem is first column do not show up.

I convert first column into link using action method. With razor it(first column) is not getting rendered in page at all. Rest of grid is fine.

What could be the problem?

@{Html.Grid(Model.Orders).Attributes(style => "width: 100%;").Columns(
column => {
    column.For(x => x.Order开发者_开发问答Number).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();}


I have moved away from using mvccontrib grid as it doesn't make much sense in grid we have.

Anyway problem was code in the question does not return html but puts code directly into response stream. And code for columns rendered using razor which put's code into stream whenever called. so it ends up putting columns into stream before grid is rendered.

It was resolved by not using razor code in action called by grid.


Ok I got it working for me with the following

 @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");


You can do a custom column to get what you want:

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

From: MvcContrib Grid Custom Columns (Razor)

I did this when porting some .aspx pages to Razor.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号