public MvcHtmlString DisplayFor <TValue>(Expression <Func <TModel, TValue> > expression, bool scopeBindingToProperty, object additionalViewData = null) { if (!scopeBindingToProperty) { return(DisplayFor(expression, additionalViewData)); } var model = ContextSwitcher.SwitchContext(expression, HtmlHelper.ViewData.Model); var container = new BindingScopeUIContainerBuilder().BuildUIContainer(expression, "div", additionalViewData); var newHelper = HtmlHelperFactory.BuildHtmlHelper(HtmlHelper.ViewContext, model); var builder = new KnockoutUIBuilder <TValue>(newHelper, ContainerBuilder); container.InnerHtml = builder.DisplayForModel(false, additionalViewData).ToHtmlString(); return(new MvcHtmlString(container.ToString())); }
public MvcHtmlString EditorViewFor <TValue>(Expression <Func <TModel, TValue> > expression, string stateManagerName, EditorViewConfig config, bool scopeBindingToProperty) { var esmHelper = new EditStateManagerHelper(stateManagerName); var model = ContextSwitcher.SwitchContext(expression, HtmlHelper.ViewData.Model); var newHelper = HtmlHelperFactory.BuildHtmlHelper(HtmlHelper.ViewContext, model); var knockoutBuilder = new KnockoutUIBuilder <TValue>(newHelper, ContainerBuilder); var editor = new TagBuilder("div"); editor.MergeAttribute("data-bind", esmHelper.VisibleWhenEditingBinding); editor.InnerHtml = knockoutBuilder.EditorForModel().ToHtmlString(); var display = new TagBuilder("div"); display.MergeAttribute("data-bind", esmHelper.VisibleWhenReadonlyBinding); display.InnerHtml = knockoutBuilder.DisplayForModel().ToHtmlString(); var footer = new TagBuilder("footer"); footer.InnerHtml = EditorCommandControls(esmHelper, config).ToString(); var containerHtmlStringBuilder = new StringBuilder(); containerHtmlStringBuilder.Append(display); containerHtmlStringBuilder.Append(editor); containerHtmlStringBuilder.Append(footer); var containerBuilder = scopeBindingToProperty ? new BindingScopeUIContainerBuilder() : new UIContainerBuilder(); var container = containerBuilder.BuildUIContainer(expression, "div"); container.AddCssClass("editor-control"); container.InnerHtml = containerHtmlStringBuilder.ToString(); return(new MvcHtmlString(container.ToString())); }