0

I have a partial view that I load in a page passing in a parameter. When the page loads, I setup two parameters helpMember and helpAnonymous.

{
  var helpMember = Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("contextualHelp", StringComparison.CurrentCultureIgnoreCase)).ElementAt(0);
  var helpAnonymous = Model.Content.Children.Where(c => c.DocumentTypeAlias.Equals("contextualHelp", StringComparison.CurrentCultureIgnoreCase)).ElementAt(1);
}
<div id="contextual-help-partial" >
    @Html.Partial("ContextualHelp", helpMember)
</div>

With jQuery, how can I reload the Partial and pass helpAnonymous to it?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Mike
  • 2,391
  • 6
  • 33
  • 72
  • 1
    You would need to return the Partial from an AJAX request which updates the existing HTML, something like this: https://stackoverflow.com/questions/3651171/asp-net-mvc-rendering-partial-view-with-jquery-ajax – Rory McCrossan Jul 28 '17 at 08:30

1 Answers1

1

You have to create one method in controller and call that action using this. Suppose created action as loadhtml. return partialview from that action.

Controller action as

public ActionResult loadhtml(string helpMember){
   ViewBag.helpMember = helpMember;
   return PartialView("ContextualHelp");
}

jquery code as

    $.ajax({
        type: 'GET',
        url: "/loadhtml?helpMember=@helpMember",
        datatype:"html",
        success: function (data) {
           $("#contextual-help-partial").empty().html(data);
        },
        error: function (err) {
        }
    });
jignesh patel
  • 964
  • 7
  • 13