Bootbox ASP MVC Razor partial view?

北城余情 提交于 2020-01-25 18:01:35

问题


I am using bootbox widget to display bootstrap modal.

http://bootboxjs.com/examples.html

What i need is to load Razor partial view in bootbox modal

This works ok

$(".permissions-popup").click(function () {
    bootbox.dialog({
        title: "Icons description.",
        message: '<div class="alert">Hello</div>',
        buttons: {
            main: {
                label: "Close",
                className: "btn-primary",
                callback: function () {
                }
            }
        },
        className: "modal-large"
    }
   );
});

But when i try something like this

$(".permissions-popup").click(function () {
    bootbox.dialog({
        title: "Icons description.",
        message: '@Html.Partial("_ConentInfo")',
        buttons: {
            main: {
                label: "Close",
                className: "btn-primary",
                callback: function () {
                }
            }
        },
        className: "modal-large"
    }
   );
});

It doesn not work i got error like this

SyntaxError: unterminated string literal

Is ti possible to load partial view in bootbox widget, i know i can to that with plain bootstrap modal, but i need bootbox?


回答1:


Install-Package Newtonsoft.Json

Inside razor view:

@using Newtonsoft.Json

then you can create a javascript object:

var bootboxDialogMessage = @(Html.Raw(JsonConvert.SerializeObject(Html.Partial("_ConentInfo").ToString().Trim('"'))));

and use it in your even inside a script file bootboxDialogMessage

Note: This adds unnecessary overhead imo, just go with your first way. I am using this only in a case that I am passing a model in my partial view.



来源:https://stackoverflow.com/questions/27617852/bootbox-asp-mvc-razor-partial-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!