I am using grid-stack for drag/drop functionality in my asp.net mvc web application.

I have an "Add Widget" button....

<button class="btn btn-white btn-primary" id="addwidget" type="submit">Add Widget</button>

I also have a bunch of MVC5 partial pages (Razor), one file for each "widget". When I click the "Add Widget" button I want to insert a widget onto the page. Right now here is the js code for the click event of the button...

        $('#addwidget')
        .click(function () {
            var grid = $('.grid-stack').data('gridstack');
            var partialView = @Html.Partial("~/Views/Widgets/_MyImportLatest.cshtml").ToHtmlString();
            grid.addWidget($('<div class="ibox-content" style="height:160px;">' + partialView + '</div>'), 0, 0, 3, 2, true);
        });

Yes, that's Razor code mixed in with js. And, unfortunately it doesn't like partialView at all, as you may have guessed.

I'm trying to basically get the resulting partial view into a string so that I can use that html string in the addWidget function. If I hardcode partialView this works and the widget is added.

Any ideas? Thanks!

Related posts

Recent Viewed