1

Beeing new to Ajax i need help with how to add the querystring and invoke the Index action without a postback. Now the link looks like this:

<a href="@EPiServer.UriSupport.AddQueryString(Request.RawUrl, "section", Server.UrlEncode(sectionGroup.Term))">@sectionGroup.Term, @sectionGroup.Count</a>

My guess is using Ajax.ActionLink but how do i create the querystring?

tereško
  • 58,060
  • 25
  • 98
  • 150
Andy
  • 503
  • 3
  • 15
  • 29

1 Answers1

1

Everything that you add to the routeValues and doesn't match a route segment will be added to the querystring.

Using your example, it would look something like this with Ajax.ActionLink:

@Ajax.ActionLink(
    sectionGroup.Term + ", " + sectionGroup.Count, 
    "Index", 
    new { section = sectionGroup.Term }, 
    new AjaxOptions { UpdateTargetId = "id-of-container" }
)

In your Index action you need to return a partial view when it is requested with ajax. This will remove the layout (master page) from the response.

if (Request.IsAjaxRequest())
    return PartialView(model);

return View(model);

Remember to add a reference to the jquery.unobtrusive-ajax.js file.

aolde
  • 2,287
  • 16
  • 19