本文整理汇总了C#中Models.ToJsonString方法的典型用法代码示例。如果您正苦于以下问题:C# Models.ToJsonString方法的具体用法?C# Models.ToJsonString怎么用?C# Models.ToJsonString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Models
的用法示例。
在下文中一共展示了Models.ToJsonString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GoogleMap
private static MvcHtmlString GoogleMap(HtmlHelper helper, string id, Models.Map map, bool editor)
{
StringBuilder sbControlHtml = new StringBuilder();
using (StringWriter stringWriter = new StringWriter())
{
using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter))
{
//Generate container div control
HtmlGenericControl divWrapperControl = new HtmlGenericControl("div");
HtmlGenericControl divMapControl = new HtmlGenericControl("div");
divMapControl.Attributes.Add("class", "map-container");
divMapControl.Attributes.Add("id", string.Format("map-{0}", id));
if (map.height > 0 || map.width > 0)
{
string widthStyle = "width:{0}px;";
if (map.width > 0)
{
widthStyle = string.Format(widthStyle, map.width);
}
else
{
widthStyle = string.Empty;
}
string heightStyle = "height:{0}px;";
if (map.height > 0)
{
heightStyle = string.Format(heightStyle, map.height);
}
else
{
heightStyle = string.Empty;
}
divMapControl.Attributes.Add("style", string.Concat(widthStyle, heightStyle));
}
divWrapperControl.Controls.Add(divMapControl);
//value input control
HtmlInputHidden hidden = new HtmlInputHidden();
HtmlInputHidden hiddenValueControl = new HtmlInputHidden();
hiddenValueControl.ID = id;
divWrapperControl.Controls.Add(hiddenValueControl);
HtmlGenericControl scriptControl = new HtmlGenericControl("script");
scriptControl.Attributes.Add("type", "text/javascript");
scriptControl.InnerHtml = string.Format(@"$(document).ready(function(){{
$('#map-{0}').GoogleMapEditor($.extend({{}},{1},{{dataChange:function(sender, data){{ $(sender.container).next().next().val(data); }}}}));}});", id, map.ToJsonString());
divWrapperControl.Controls.Add(scriptControl);
divWrapperControl.RenderControl(htmlWriter);
sbControlHtml.Append(stringWriter.ToString());
divWrapperControl.Dispose();
}
}
return new MvcHtmlString(sbControlHtml.ToString());
}