0

I have a some partial views that generally make use of small model data. I have been using Ajax.BeginForm to with js functions defined in the AjaxOptions to catch the partial postback's success or failure when that part is submitted.

I saw no performance penalty as my data has been light. Currently, I have been working on a piece that returns an HTMLFragment from an SSRS report rendered as format "HTML40" in the controller. The JSON serialization of the html portion is taking a long time and I no longer see it as an option. When I changed the Ajax.BeginForm to Html.BeginForm and rendered the report upfront then the payload is lighter and takes less time to render but now I am stuck. How do I issue refresh commands without loading the partial again? This is why I used Ajax.BeginForm in the first place :( Perhaps there is a better way to load the data than what I am doing. I have started looking into callbacks and somehow getting the report pieces a raw byte[] or string as opposed to using json serialization.

Thanks

1 Answer 1

2

You can load a whole partial into a div using .load() jQuery function:

$("#someButton").click(function(){
  $("#someDive").load("/url", {type: 'POST'}, function(){
  });
});

Now, when you click on #someButton, an AJAX call will be made to /url. The /url can return a PartialView that will be loaded directly into your div:

//controller URL
[HttpPost]
public ActionResult Index(){
    return PartialView("MyPartialView");
}

You can pass in models as you'd do to regular view.

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

1 Comment

Yea thanks. That would add another abstraction layer to what I am doing with the page->partial. It would be like page->partial->partial. I was hoping to avoid having a too many moving parts.

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.