예제 #1
0
 public static MvcHtmlString JsonModel <M, T>(this HtmlHelper <M> htmlHelper, string name, T value, IDictionary <string, object> htmlAttributes = null, bool translateBack = false)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         throw(new ArgumentNullException("name"));
     }
     if (translateBack)
     {
         RenderInfo <T> renderInfo = new RenderInfo <T>(
             htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(name),
             name,
             string.Empty,
             value);
         var h = htmlHelper.RenderWith(
             htmlHelper.InvokeTransform(
                 renderInfo,
                 new SipleModelTranslator <T>()));
         return(h.HiddenFor(m => m.JSonModel, htmlAttributes));
     }
     else
     {
         return(htmlHelper.Hidden(name, value == null ? null : BasicHtmlHelper.ClientEncode(value), htmlAttributes));
     }
 }
예제 #2
0
        public static MvcHtmlString DetailFormSyncInfos <TItem, T>
            (this HtmlHelper <TItem> htmlHelper,
            Expression <Func <TItem, T> > expression,
            string formattedValue,
            bool htmlEncode = true,
            string urlValue = null)
        {
            if (expression == null)
            {
                throw (new ArgumentException("expression"));
            }
            string trueValue = string.Empty;
            string id        = BasicHtmlHelper.IdFromName(
                BasicHtmlHelper.AddField(
                    htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix,
                    ExpressionHelper.GetExpressionText(expression)));

            if (!typeof(IConvertible).IsAssignableFrom(typeof(T)))
            {
                T model = default(T);
                try{
                    model = expression.Compile().Invoke(htmlHelper.ViewData.Model);
                }
                catch {
                }
                trueValue = string.Format(
                    "var {0}_True = '{1}'; ",
                    id,
                    htmlHelper.Encode(BasicHtmlHelper.ClientEncode(model)));
            }
            string fUrlValue = string.Empty;

            if (urlValue != null)
            {
                fUrlValue = string.Format(
                    "var {0}_Url = '{1}'; ",
                    id,
                    htmlHelper.Encode(urlValue));
            }
            string fFormattevValue = string.Empty;
            string html            = string.Empty;

            if (formattedValue != null)
            {
                if (htmlEncode)
                {
                    fFormattevValue = string.Format(
                        "var {0}_Format = '{1}'; ",
                        id,
                        htmlHelper.Encode(formattedValue));
                }
                else
                {
                    html = string.Format(
                        @"<span id='{0}_Format' style='display:none'>
                        {1}
                        </span>
                        ",
                        id,
                        htmlHelper.Encode(formattedValue));
                    fFormattevValue = string.Format(
                        @"var {0}_Format = '<>'; ",
                        id);
                }
            }
            return(MvcHtmlString.Create(
                       string.Format(syncScript, trueValue, fUrlValue, fFormattevValue, html)));
        }
예제 #3
0
 public void ImportFromModel(object model, params object[] context)
 {
     JSonModel = BasicHtmlHelper.ClientEncode(model);
 }