【发布时间】:2012-02-08 10:05:53
【问题描述】:
我在我的ASP.NET MVC3 应用程序上使用最新版本的Telerik MVC 控件和razor。
我的网格结构定义如下:
@(Html.Telerik()
.Grid<GrantApplicationListViewModel>()
.Name("grdGrantApplications")
.Columns(column =>
{
column.Bound(x => x.FullName)
.Title("Owner")
.Width(200);
column.Bound(x => x.CreatedDate)
.Title("Created")
.Width(90);
})
.DataBinding(dataBinding => dataBinding.Ajax().Select("AjaxGrantApplicationsBinding", "Home"))
.Pageable(paging => paging.PageSize(30))
.TableHtmlAttributes(new { @class = "telerik-grid" })
)
我的视图模型如下所示:
public class GrantApplicationListViewModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get { return FirstName + " " + LastName; }
}
public DateTime CreatedDate { get; set; }
}
我创建了一个日期格式化程序,我想在我的专栏中使用它来格式化日期:
public static class DateTimeExtensions
{
public static string FormatDate(this DateTime instance)
{
return string.Format("{0:yyyy-MM-dd}", instance);
}
}
如何在我的专栏中使用这种格式化方法来格式化 CreatedDate?我尝试了以下方法:
column.Bound(x => x.CreatedDate.FormatDate())
.Title("Created")
.Width(90);
..我收到以下错误:
Bound columns require a field or property access expression.
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-2