Example #1
0
        public MvcHtmlString EditorFor <TValue>(Expression <Func <TModel, TValue> > expression, bool scopeBindingToProperty = false, object additionalViewData = null)
        {
            if (!scopeBindingToProperty)
            {
                return(EditorFor(expression, additionalViewData));
            }

            var model     = ContextSwitcher.SwitchContext(expression, HtmlHelper.ViewData.Model);
            var container = new BindingScopeUIContainerBuilder().BuildUIContainer(expression, "ol", additionalViewData);
            var newHelper = HtmlHelperFactory.BuildHtmlHelper(HtmlHelper.ViewContext, model);

            var builder = new KnockoutUIBuilder <TValue>(newHelper, ContainerBuilder);

            container.InnerHtml = builder.EditorForModel(false, additionalViewData).ToHtmlString();

            return(new MvcHtmlString(container.ToString()));
        }
Example #2
0
        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()));
        }