i’m wondering how to control whether a column is visible in a Html.Grid if nothing has been returned in the list. So if in the below example Model.Comment doesn’t have a value in the ExampleList, then the column should not be rendered.
@Html.Grid(Model.ExampleList).Columns(c =>
{
c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateRequested)).Named("Date Requested");
c.For(a => a.Comment).Named("Comment");
c.For(a => a.Completed).Named("Completed");
})
How can this be achieved?
You should use a view model and inside this view model you should have a boolean property indicating whether something should be visible or not. Obviously all the logic about determining its value is not the view responsibility => it’s the controller or the model. So for example you could have the following view model:
and then in the view: