0

I want to load data in the background while the user is on the page. After the data is loaded, I want to display it by using a partial View. So I wrote this:

var serviceURL = '/Vm/GetInformation';
$.ajax({
    type: "POST",
    url: serviceURL,
    data: param = "",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: { "id": id },
    //success: resetPartial()
});

In my controller:

public ActionResult GetInformation()
{
    myCode...
    return PartialView("_List", Costumer);
}

So what is the final step to display that _List partial View in my main view which is now filled with data about costumers (where my ajax function is)

Thank you

1
  • @Brian Mains answer should help you, but the way I load partial view is with the load() method from jquery. What you could use is your url as string as you are using it, and then specify a div to load your partial view $("#divToLoad").load(url); where url is your url string to the server Commented Dec 8, 2014 at 16:29

2 Answers 2

1

All you need to do is replace the old content:

success: function(d) {
 //d should be a string that's the HTML markup
 $("#someparentelementthatsurroundsinnercontent").html(d);
}

Or you can use any of the methods to append content if you want to append to the end of the list. JQuery gives quite a few options to do this.

Sign up to request clarification or add additional context in comments.

2 Comments

So how should the HTML markup exactly look? I wrote something like var d = 'Html.RenderPartial("~/Views/Shared/_List.cshtml", Model);';
Ummm where is d involved? You don't need to manually create d, it's the return parameter from the success callback... Plus, that statement can only evaluate on initial rendering, which is not what you want.
0

Your controller action expects no parameter. So you can remove the below lines from your ajax call.

data: param = "",
data: { "id": id },

If you really have any parameter id in your controller action, use it like

data: { id:id } 

Have a div in the html to hold the content of the partial view. In the success, use like below:

success : function(result) {
  $("#partialViewHolder").html(result);
}

Comments

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.