PartialView, Ajax call and script.

Topics: Troubleshooting, Writing modules
May 2, 2013 at 2:43 PM
Hello.
I've partial view definied:
@using (Script.Head())
{
    @Html.Raw(Model.Head)
}

<div>
    @Html.Raw(Model.Body)
</div>
That partial view is called form other view via ajax call:
$(document).ready(function (e) {
            var url = '@Url.Action("MyPartial" })';
            $.ajax({
                type: "GET",
                url: url,
                data: null,
                async: true,    
                success: function (result) {
                    $("#MainContent").html(result);
                },
                error: function (req, status, error) {
                    $("#MainContent").html('Error');
                }
            });
        });
The problem is that Orchard is completely ignoring Script.Head() when rendering partial view via ajax, so view is loaded without neccessary scripts.

If you ask - no, I can't do it in other way. Ajax call wil be used to show indictator while loading - it takes some time.

I've found sth here, but I can't see how it could help me. My script head is generating dynamically, so I can't put it in js file.
May 3, 2013 at 4:45 PM
Like Piedone says on the post:

Partial views via the ajax request should not have a layout assigned. Therefore there are no zones, and no where for the scripts shape(s) to render.

You can still have partial views use the Script.Head (i do) etc when the partial views are rendered with a view rather than a step after through ajax.
You can still bring scripts back via the Ajax call by removing the @using (Script.Head()) bit. I tend to step away from dragging scripts back via ajax requests though, it only insights a mess of HTML and JavaScript.

Can't you run the scripts.head bit on the parent view? Where is it coming from as well? A database, rendered on the fly, purpose? I really would try and get it there before the page is served.

Matt