I'm new to asp.net mvc as well as kendoui so this question may seem trivial (for both kendo and mvc). But any help/explanation would be greatly appreciated.
I'm building a grid using the kendo ui mvc helper. And there are many situations where I want to access item data. I've figured out how to access it when created a template for a given cell as seen below.
As you can, I've created a function to create a data attribute, and I would like to read that attribute from the database rather than hardcoding it. Here is the code that I currently have.
@functions
{
public static Dictionary<string, object> BuildGroupNameAttributes(string value)
{
var attributes = new Dictionary<string, object> { { "data-groupname", value } };
return attributes;
}
}
<div id="dotComDiv">
@(Html.Kendo().Grid(Model)
.Name("DotComGrid")
.Columns(columns =>
{
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes("Gross Demand"));
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes("Gross Demand")).Template(@<text>@string.Format("{0:0,0}", @item.GrossDemand.ThisYear)</text>);
}).Scrollable(src => src.Height(500))
)
</div>
The line that I can't seem to work out is
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes("Gross Demand"));
Instead of hardcoding "Gross Demand" I want to read that from the bound item. So like,
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes(@item.GroupName));
However, I can't access the item object like this. But if you look at the template above, I'm able to access `@item` if it's wrapped in `@<text>`
Why is that, and how can I pass the item value to the function?
Thanks!
I'm building a grid using the kendo ui mvc helper. And there are many situations where I want to access item data. I've figured out how to access it when created a template for a given cell as seen below.
As you can, I've created a function to create a data attribute, and I would like to read that attribute from the database rather than hardcoding it. Here is the code that I currently have.
@functions
{
public static Dictionary<string, object> BuildGroupNameAttributes(string value)
{
var attributes = new Dictionary<string, object> { { "data-groupname", value } };
return attributes;
}
}
<div id="dotComDiv">
@(Html.Kendo().Grid(Model)
.Name("DotComGrid")
.Columns(columns =>
{
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes("Gross Demand"));
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes("Gross Demand")).Template(@<text>@string.Format("{0:0,0}", @item.GrossDemand.ThisYear)</text>);
}).Scrollable(src => src.Height(500))
)
</div>
The line that I can't seem to work out is
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes("Gross Demand"));
Instead of hardcoding "Gross Demand" I want to read that from the bound item. So like,
columns.Bound(p => p.GrossDemand.ThisYear).Title("TY").HeaderHtmlAttributes(BuildGroupNameAttributes(@item.GroupName));
However, I can't access the item object like this. But if you look at the template above, I'm able to access `@item` if it's wrapped in `@<text>`
Why is that, and how can I pass the item value to the function?
Thanks!