I need distinct records by mouth, but I have a error:
Column “data” does not exist.
Server Error in '/' Application.
Column "data" does not exist.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Column "data" does not exist.
Source Error:
Line 14: var grid = new WebGrid(ViewBag.dat ,null, "Dates", 8);
Line 15: }
Line 16: @grid.GetHtml(
Line 17: tableStyle: "grid",
Line 18: headerStyle: "head",
My Controller:
var d = (from b in baza.hours
where b.userID == userID
select new { b.data.Month }).Distinct();
ViewBag.dat = d;
And my View:
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
@{
var grid = new WebGrid(ViewBag.dat ,null, "Dates", 8);
}
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("data","Dates")
)
)
</fieldset>
}
How fix it?
Try like this:
You are returning an anonymous object to your view. Or more precisely a collection of anonymous objects each having a property called
Month. So you should useMonthas column name in your markup.