I am using an Ajax Binding on a Telerik MVC grid and I can't figure out how I would resolve the text version of an enum within the ClientTemplate.
Given:
enum MyEnum { Sat, Sun, Mon, Tue, Wed, Thu, Fri };
public class MyBusinessObject{
public int Id { get; set; }
public MyEnum Day { get; set;
}
In my view:
@(Html.Telerik().Grid<MyBusinessObject>()
... columns.Bound(o => o.Day) .ClientTemplate("????")
How can I resolve, for example, "Mon" within the column using the ClientTemplate
?
No matter what you type inside the ClientTemplate you wont be able to display it properly. Because the action method handling the Select operation of your Grid will use the default settings for the JavaScriptSerializer and your the values represeting your Enum property will be Integers - you can check what is the response of your select method.
You can try to use some JavaScript function which transforms there integers into strings again back on client - if you take this approach then you can type some JavaScript function which will be called each time on the client when the template is needed.
For example:
ClientTemplate("myTransformFunction('<#= MyEnumProperty#>')")
This way a function will be called and the integer representation of the enum will be passed - you can then use a simple switch to return the appropriate string.
Or an easier approach would be to use the ViewModel pattern.