Exemplo n.º 1
0
        internal static IHtmlString RenderActionTemplate(
            HtmlHelper html, 
            object formattedValue, 
            string htmlFieldName, 
            ModelMetadata metadata, 
            IDictionary<string, object> editorAttributes)
        {
            var settings = metadata.GetRenderActionSetting();

            Throw.IfNullArgument(settings, "RenderAction settings not found");
            Throw.IfNullArgument(settings.Action, "RenderAction is not initialized");

            var htmlFieldPrefix = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName);
            var viewData = new ViewDataDictionary(html.ViewData)
            {
                Model = metadata.Model,
                ModelMetadata = metadata,
                TemplateInfo = new TemplateInfo()
                {
                    FormattedModelValue = formattedValue,
                    HtmlFieldPrefix = htmlFieldPrefix
                }
            };

            ViewContext viewContext = new ViewContext(
                (ControllerContext)html.ViewContext,
                html.ViewContext.View,
                viewData,
                html.ViewContext.TempData,
                html.ViewContext.Writer);

            var htmlLocal = new HtmlHelper(viewContext, new ViewDataContainer(viewData));

            return settings.Action(htmlLocal);
        }