开发者

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

开发者 https://www.devze.com 2023-03-29 14:05 出处:网络
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?
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

精彩评论

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