protected override object ExecuteBind(BindingContext context) { ValueProviderResult value; if (!context.TryGetValue(out value)) return null; string stringValue = value.GetValue<string>(); if (String.IsNullOrEmpty(stringValue)) return null; ModelStateSerializer serializer = new ModelStateSerializer(); return serializer.Deserialize(stringValue, _mode); }
public static string Serialize(this HtmlHelper helper, string name, object data, SerializationMode mode) { Precondition.Require(helper, () => Error.ArgumentNull("helper")); Precondition.Defined(name, () => Error.ArgumentNull("name")); ModelStateSerializer serializer = new ModelStateSerializer(); string elementName = helper.Context.ViewData.Template.GetHtmlElementName(name); string value = serializer.Serialize(data ?? helper.Context.ViewData.Model, mode); HtmlElementBuilder builder = new HtmlElementBuilder("input"); builder.Attributes["type"] = "hidden"; builder.Attributes["name"] = elementName; builder.Attributes["value"] = value; return builder.ToString(); }
public static string Serialize(this HtmlHelper helper, string name, object data, SerializationMode mode) { Precondition.Require(helper, () => Error.ArgumentNull("helper")); Precondition.Defined(name, () => Error.ArgumentNull("name")); ModelStateSerializer serializer = new ModelStateSerializer(); string elementName = helper.Context.ViewData.Template.GetHtmlElementName(name); string value = serializer.Serialize(data ?? helper.Context.ViewData.Model, mode); HtmlElementBuilder builder = new HtmlElementBuilder("input"); builder.Attributes["type"] = "hidden"; builder.Attributes["name"] = elementName; builder.Attributes["value"] = value; return(builder.ToString()); }
protected override object ExecuteBind(BindingContext context) { ValueProviderResult value; if (!context.TryGetValue(out value)) { return(null); } string stringValue = value.GetValue <string>(); if (String.IsNullOrEmpty(stringValue)) { return(null); } ModelStateSerializer serializer = new ModelStateSerializer(); return(serializer.Deserialize(stringValue, _mode)); }