首页 文章

html 助手中的 Html 助手(从字符串文字中正确呈现剃刀)

提问于
浏览
-1

我为联系模式制作了一个自定义的 HTML 帮助器,以便我们的应用程序中的任何人都可以使用它与@Html.ContactModal(model 和选项在这里),但问题是在模态上有另一个 html 助手,销售代码下拉,剃刀是没有没有正确渲染。我尝试用局部视图做所有事情只是为了了解你不能(或者不应该)使用部分和 html 助手,只有控制器(我是 this...)的所有人,co-worker 建议我使用标签构建器,但是我想在用标签构建器编写整个表单之前先问这里。

public static IHtmlString ContactModal(this HtmlHelper htmlHelper, ContactModalOptions options)
    {
        //required scripts
        htmlHelper.AddScriptFile("~/Areas/Customers/Scripts/ContactModal/tmi.customers.contactModal.js");
        htmlHelper.AddScriptLine("$('#" + options.controlId + "').contactModal(" + options.ToJson() + ");", true);
        string htmlContents = string.Empty;
        htmlContents = $@"<div id='contactModalContainer' style='display: none'>
<div class='panel panel-default panel-details' id='' style='display: none'>
    <div class='panel-heading' id='divContactModalHeading'>
        <h3 id='h3contactModalHeading'></h3>
    </div>
    <div class='panel-body' id='divContactDetBody'>
        <form id='custContactDetailsForm'>
            <div class='row'>
                <div class='col-sm-6'>
                    <div class='form-group' style=''>
                        <label for='txtFirstName' id='lblFirstName' class='control-label'>First Name: </label>

                        <input data-helper='FirstName' id='contactFirstName' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />

                    </div>
                </div>
                <div class='col-sm-6'>
                    <div class='form-group' style=''>
                        <label for='txtLastName' class='control-label'>Last Name: </label>
                        <input data-helper='LastName' id='contactLastName' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />
                    </div>
                </div>
                <div class='col-md-12'>
                    <div class='form-group' style=''>
                        <label for='txtPositionTitle'>Position/Title: </label>
                        <input id='contactPosition' data-helper='Position' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />

                    </div>
                </div>
                <div class='col-md-12'>
                    <div class='form-group' style=''>
                        <label for='txtSalesOrders'>E-mail: </label>

                        <input id='contactEmail' data-helper='Email' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />

                    </div>
                </div>
                <div class='col-sm-4'>
                    <div class='form-group' style=''>
                        <label for='txtSalesOrders'>Work Phone: </label>

                        <input id='contactWorkPhone' data-helper='DirectPhone' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />

                    </div>
                </div>
                <div class='col-sm-4'>
                    <div class='form-group' style=''>
                        <label for='txtMobilePhone'>Mobile Phone: </label>

                        <input id='contactMobile' data-helper='MobilePhone' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />
                    </div>
                </div>

                <div class='col-sm-4'>
                    <div class='form-group' style=''>
                        <label for='txtFax'>Fax: </label>
                        <input id='contactFax' data-helper='Fax' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />
                    </div>
                </div>

                <div class='col-sm-4'>
                    <div class='form-group' style=''>
                        <label for='txtHomePhone'>Home Phone: </label>

                        <input id='contactHomePh' data-helper='HomePhone' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />

                    </div>
                </div>

                <div class='col-sm-4'>
                    <div class='form-group' style=''>
                        <label for='txtPager'>Other Phone: </label>
                        <input id='contactPager' data-helper='PagerPhone' type='text' class='form-control' disabled='disabled' data-editable='true' value='' />
                    </div>
                </div>

                <div class='col-sm-12'>
                    <div class='form-group'>
                        <label for='txtNotes'>Notes/Comments: </label>
                        <textarea id='contactNotes' data-helper='ContactNotes' type='text' class='form-control' disabled='disabled' rows='3' data-editable='true' value=''></textarea>
                    </div>
                </div>

                <div class='col-sm-6'>
                    <div class='form-group' style=''>
                        <label for='txtDateAdded'>Date Added: </label>
                        <label id='contactDateAdded'></label>
                    </div>
                </div>

                <div class='col-sm-6' style='clear: both'>
                    <div class='form-group'>
                        <label class='control-label'>Referred By:</label>
                        <div class=''>
                            @@Html.SalesCodeDropDown(new SelectControlOptionsBase('contactReferredBy')
                       {{
                            includeNull = true,isEditable = editableOptions.yes,
                           disabled = true,
                       }})
                        </ div >

                    </ div >
                </ div >
                < div class='col-md-6' style='clear: both'>
                    <div class='form-group' style=''>
                        <label for='txtEnteredBy'>Entered By: </label>

                        <label id = 'contactEnteredBy' ></ label >

                    </ div >
                </ div >
                < div class='col-md-6' style='clear: both'>
                    <div class='checkbox'>
                        <label>
                            <input id = 'contactIsInactiveChkBx' data-helper='Inactive' type='checkbox' disabled data-editable='true' value='0'>Inactive
                          </label>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div id = 'contactModalFooter' class='form-group' style=''>
    <button type = 'button' id='btnContactModalClose' style='margin-right: 5px;' class='pull-right btn btn-form-state'>Close</button>
    <button type = 'button' id='btnContactModalCancel' style='margin-right: 5px;' class='pull-right btn btn-form-state'>Cancel</button>
    <button type = 'button' id='btnContactModalSave' style='background-color: #EE6723; margin-right: 5px;' class='pull-right btn btn-form-state'>Save</button>
</div>

“;返回 MvcHtmlString.Create(htmlContents);

2 回答

  • 1

    最终工作:

    public static IHtmlString ContactModal(this HtmlHelper htmlHelper, ContactModalOptions options)
        {
            StringBuilder result = new StringBuilder();
    
            //required scripts
            htmlHelper.AddScriptFile("~/Areas/Customers/Scripts/ContactModal/tmi.customers.contactModal.js");
            htmlHelper.AddScriptLine("$('#" + options.controlId + "').contactModal(" + options.ToJson() + ");", true);
            var body = htmlHelper.Partial("~/Areas/Customers/Views/Contacts/Shared/ContactModalPartial.cshtml").ToHtmlString();
            result.AppendLine(body);
            return MvcHtmlString.Create(result.ToString());
        }
    
  • 0

    如果您的@Html.SalesCodeDropDown(new SelectControlOptionsBase('contactReferredBy')返回 html,那么在设置变量 htmlContents 之前调用它,然后在需要的位置连接它。

相关问题