0

I am stuck in this problem for hours if not days.

I can start the ActionResult that returns PartialView("MODEL") but I am unable to render actual View into the div inside an Index cshtml page.

Here is what I am trying:

Controller:

...
public ActionResult Calendar()
    {
        PopulateCalendarAsync();
        return PartialView(_calendarViewModel);
    }
...

Index.cshtml :

<div id="calendarDiv" ></div>

script inside Index:

<script type="text/javascript">
$(document).ready(function (e) {
    $.get('@Url.Action("Calendar","Home")', {}, function (result) {
        $("#calendarDiv").load("~/Home/Calendar");

    });
});

When Index page loads, script calls the ActionResult Calendar() with no problems.

The problem is that div is not being updated.

my Calendar.cshtml page is aside Index page in Home folder.

What am I missing here?

1 Answer 1

1

The result parameter of the $.get request will contain the html output of the calendar partial view.
Assign it to the <div> via $("#calendarDiv").html(result);

Full code:

$(document).ready(function (e) {
    $.get('@Url.Action("Calendar","Home")')
        .then(function (result) {
             $("#calendarDiv").html(result);
         })
        .fail(function (xhqr, status, error) {
            alert(status);
            alert(JSON.stringify(xhqr));
        })
});
Sign up to request clarification or add additional context in comments.

6 Comments

What's the value in result?
I will need to check it, not sure how to do this in jquery... alert(result.ToString?)
just alert(result) will do.
it does not pop up
Then an error might have occurred; I updated my answer to catch any.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.