How can I serialize a client function to a json object? (similar to how kendo controls work)
This is what I have so far...
View:
@Html.TestCo
Based on @ryan's answer, I upgrade a little bit to more like kendoUI.
public class TextBox : BaseControl
{
[JsonProperty("onChange", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(JsFunctionConverter))]
public Func
Here is JsFunctionConverter:
public class JsFunctionConverter : JsonConverter
{
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}
public override bool CanRead
{
get { return false; }
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof (string) || objectType == typeof (Func
And you can do it like KendoUI
var textBox = new TextBox
{
OnChange = @
function(e){
return e;
}
};