@{IEnumerable<BC.Models.APPLICATION> data = ViewBag.list;}
@Html.Grid(data).Columns(columns =>
{
columns.Add(c => c.APPLICATION_NO).Titled("Application No").Filterable(true);
})
But i want to do something like that :
@if(some conditon)
{
@{IEnumerable<BC.Models.APPLICATION> data = ViewBag.list;}
}
else
{
@{IEnumerable<BC.Models.RIGHTS> data = ViewBag.list;}
}
@Html.Grid(data).Columns(columns =>
{
columns.Add(c => c.APPLICATION_NO).Titled("Application No");
})
But its not working can anybody have some idea about it.
Now
if i do something like this it works
@if(some conditon)
{
@{IEnumerable<BC.Models.APPLICATION> data = ViewBag.list;}
@Html.Grid(data).Columns(columns =>
{
columns.Add(c => c.APPLICATION_NO).Titled("Application No");
})
}
else
{
@{IEnumerable<BC.Models.RIGHTS> data = ViewBag.list;}
@Html.Grid(data).Columns(columns =>
{
columns.Add(c => c.APPLICATION_NO).Titled("Application No");
})
}
My problem is that APPLICATION_NO property present in both Model class so i don`t want to use
@Html.Grid(data).Columns(columns =>
{
columns.Add(c => c.APPLICATION_NO).Titled("Application No");
})
Twice in my code.
The code can't work because data is declared into if blocks. If the grid has to work only on shared fields of the two classes you can think about using an Interface that APPLICATION and RIGHTS will implement and change the code like this:
where IAPPLICATION_NO is an interface like:
I don't know what APPLICATION_NO is, so I used string and the interface can define only get for grid.
Otherwise, if you need to display different data for those two types you should consider using two views or different grid declaration in the if blocks.
I worked on a sample of my answer on VS:
I attach you the code:
these are the classes
now the controller:
and the view:
this solves your problem as you can see
Without using interfaces:
but you lose the IntelliSense completion and if the member is missing I think you receive a runtime error.
I tried your Grid assembly but it uses c# Expression and it's incompatible with dynamic. Another solution could be casting one list to another using LINQ in the controller:
In the view you can keep the working code you posted at the top of the question. You have not multitype IEnumerable support because you use only one type but without using a common interface between these classes I think we must go to reflection but I think it's hard to write that code.