Is it possible to make use of the UIHint attribute on a model property such as -
In order to specify a DisplayTemplate partial as a Template for grid data?
We have a fairly generic grid HTML helper method that uses model attributes whilst binding -
The grid has a dynamic model which is based partially on a fixed ViewModel and partially on dynamic fields which are created and managed by the users within the database (and thus cannot be known in advance). As such the binding is programmatic and not directly to a model. The dynamic fields do not require a display template, I simply wanted to provide some context around our approach.
The line that builds up the columns from the fixed ViewModel is-
modelProperties.ForEach(p => columns.Bound(p.GetPrevailingType(), p.Name).Format(p.GetFormatString()).HtmlAttributes(p.GetHtmlAttributes()).Width(InitialColumnWidth));
Can I add the "ClientTemplate" method to load a partial based on the UIHint value for the property, perhaps use @Html.DisplayFor(), or must this be explicit text?
[Display(Name = "Days Late"), UIHint("_DaysToDate"), ReadOnly(true)]
public int? DaysLate
{
get; set;
}We have a fairly generic grid HTML helper method that uses model attributes whilst binding -
private static GridBuilder<dynamic> CreateDynamicGrid<TBaseViewModelType>(this HtmlHelper helper, string gridName, string provisioningControllerName, string formActionName = "Edit", bool checkboxRowSelect = false)
{
var type = typeof(TBaseViewModelType);
var modelProperties = type.GetProperties().Where(p => p.IsScaffoldable()).ToList();
var identityProperty = type.GetProperty("Id");
var idFieldName = string.Empty;
if (identityProperty != null)
{
idFieldName = identityProperty.Name;
}
return helper.Kendo().Grid<dynamic>()
.Name(gridName)
.Columns(columns => {
columns.Template(t => t).ClientTemplate("<input class='select-row' type='checkbox' />").HeaderTemplate(t => "<input class='select-all-rows' type='checkbox' />").Width(40).Visible(checkboxRowSelect);
columns.Template(t => t).ClientTemplate(helper.ActionLink(VisionWebResources.Action_More, formActionName, provisioningControllerName, new { id = string.Format("#= {0} #", idFieldName) }, null).ToHtmlString()).Visible(identityProperty != null).Width("4em");
modelProperties.ForEach(p => columns.Bound(p.GetPrevailingType(), p.Name).Format(p.GetFormatString()).HtmlAttributes(p.GetHtmlAttributes()).Width(InitialColumnWidth)); })
.DataSource(ds => ds.Ajax()
.PageSize(15) .Read(r => r.Action("Read", provisioningControllerName))
.Model(model =>
{
model.Id("Id");
foreach (var property in modelProperties) {model.Field(property.Name, property.GetPrevailingType));
}
})
)
.Editable(ed => ed.Enabled(false))
.Events(events => events.DataBound("function() { " +
"if (typeof (gridDataBound) === 'function') { gridDataBound(); }" + "}").Change("function() { " +
"if (typeof (gridFocusedRowChanged) === 'function') { gridFocusedRowChanged(); }" +
"}"))
.Filterable() .HtmlAttributes(new { @class = "grid" })
.Navigatable()
.Pageable(pages =>
{
pages.PageSizes(new[] { 15, 25, 40 });
pages.Refresh(true); //Provides a button to refresh the current grid page
}) .Resizable(resize => resize.Columns(true))
.Scrollable(scrollable => scrollable.Height(425))
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.Sortable(sortable => sortable.AllowUnsort(false));
}The grid has a dynamic model which is based partially on a fixed ViewModel and partially on dynamic fields which are created and managed by the users within the database (and thus cannot be known in advance). As such the binding is programmatic and not directly to a model. The dynamic fields do not require a display template, I simply wanted to provide some context around our approach.
The line that builds up the columns from the fixed ViewModel is-
modelProperties.ForEach(p => columns.Bound(p.GetPrevailingType(), p.Name).Format(p.GetFormatString()).HtmlAttributes(p.GetHtmlAttributes()).Width(InitialColumnWidth));
Can I add the "ClientTemplate" method to load a partial based on the UIHint value for the property, perhaps use @Html.DisplayFor(), or must this be explicit text?