Custom column in MvcContrib Grid

720 views Asked by At

I am using mvc and mvccontrib grid for the first time. I have my mvcContrib grid like so:

<%Html.Grid(Model.Results)
            .RowAttributes(row => new Hash(@class => row.Item.CadPriority1 ? "redgrid" : row.IsAlternate ? "alternategrid" : "grid"))
            .Columns(column =>
            {
                column.For(c =>
                    (c.ExistsInPatRec == true) ?
                    Html.ActionLink(c.CaseNumber.ToString(), "Details", new { id = c.CaseNumber }, new { target = "_blank" })
                    : Html.Label(c.CaseNumber.ToString())
                    )
                    .Named("Case Number").SortColumnName("CaseNumber")
                    .Encode(false)
                    ;
 column.For(c => c.ProblemDesc).Named("Problem Code").SortColumnName("ProblemCode");
 column.For(c => c.DispatchDesc).Named("Dispatch Code").SortColumnName("DispatchCode");
})
.Sort(Model.SortOptions)%>

Now,I want to add an image(based on a condition) in the first column - next to the link. How can I achieve this?

1

There are 1 answers

0
ThisGuy On

Build the HTML with a string.Format. Something like this:

c.ExistsInPatRec 
 ? string.Format("<a href='{0}' target='_blank'>Details</a><img src='{1}' />"
    Url.Action(c.CaseNumber.ToString(), new { id = c.CaseNumber }),
    urlToImage)
 : Html.Label(c.CaseNumber.ToString()))