Esempio n. 1
0
        public ActionResult ResponsiveImageTemplate(ResponsiveImageUtils.ResponsiveImageObject imageObject)
        {
            var result = new JsonResult();

            try
            {
                var html = ContentUtils.RenderPartialViewToString(
                    "~/Views/Shared/Partials/_ResponsiveImagePartial.cshtml", imageObject, ControllerContext, ViewData,
                    TempData);

                result.Data = new { success = true, html };
            }
            catch (Exception err)
            {
                result.Data = new { success = false, error = err };
            }

            return(result);
        }
Esempio n. 2
0
        public string GetHtml(Dictionary <string, string> parameters)
        {
            var model = new ResponsiveImageUtils.ResponsiveImageObject
            {
                ClassName = parameters != null && parameters.ContainsKey("class") ? parameters["class"] : "responsive-image",
                Sizes     = ResponsiveImageUtils.ResponsiveImageSizes,
                ImagePath = "",
                AltText   = "",
                Width     = 0,
                Height    = 0
            };

            if (parameters != null && parameters.ContainsKey("sizes") && !String.IsNullOrEmpty(parameters["sizes"]))
            {
                model.Sizes = parameters["sizes"];
            }

            if (parameters != null && parameters.ContainsKey("src") && !String.IsNullOrEmpty(parameters["src"]))
            {
                model.ImagePath = parameters["src"];
            }

            if (parameters != null && parameters.ContainsKey("alt") && !String.IsNullOrEmpty(parameters["alt"]))
            {
                model.AltText = parameters["alt"];
            }

            if (parameters != null && parameters.ContainsKey("width") && !String.IsNullOrEmpty(parameters["width"]))
            {
                model.Width = Convert.ToInt16(parameters["width"]);
            }

            if (parameters != null && parameters.ContainsKey("height") && !String.IsNullOrEmpty(parameters["height"]))
            {
                model.Height = Convert.ToInt16(parameters["height"]);
            }

            return(DynamicModules.GetViewHtml("Partials/_ResponsiveImagePartial", model));
        }