问题
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