开发者

MVC webgrid - can you hide a column? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

MVC 3 Webgrid - how do you hide columns you do not want to be visible?

I am using a WebGrid in my MVC application. What I want to do is put an if statement inside my form to hide a column depending on the condition. The code below shows what I mean with the if statement, but this is not allowed;

@grid开发者_StackOverflow中文版.GetHtml(columns: grid.Columns(
    grid.Column(format: (item) => Html.ActionLink("Select", "Details", new { contractId = item.ContractId })),
    if(Context.User.IsInRole(ITOF.Web.Models.Role.Inputter)
    {
        grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { contractId = item.ContractId })),
    }
    grid.Column("SignOffDate", "Sign Off Date",
        format:@<text> <span>@item.SignOffDate.ToString("d/M/yyyy")</span></text>),
    grid.Column("FullContractNumber", "Contract Number"),
    grid.Column("ContractTitle", "Title")
));


I don't know if this works, because I don't know the inner workings of the helper. You probably could do something like this:

    @{
        var temp = grid.GetHtml(....);        

        if(Context.User.IsInRole(ITOF.Web.Models.Role.Inputter)
        {
            temp.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { contractId = item.ContractId })),
        }
    }

    @Html.Raw(temp);

The helper should return an grid object not a string, otherwise you can't add the columns anymore.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜