Search code examples
asp.net-mvcasp.net-mvc-3webgrid

Ajax.Actionlink, partial and webgrid issue


I have the following issue.

My url structure is like this:

/people/edit/usercode

In my controller i have the following:

    [AcceptVerbs(HttpVerbs.Post)]
    public PartialViewResult LoanRefresh(string id)
    {
        PeopleModel p = new PeopleModel();
        return PartialView("_LoanHistory", p.getPersonLoanHistory(id));

    }

In my view i have:

@Ajax.ActionLink("Refresh", "LoanRefresh", new { id = Model.IdentityCode }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "loanHistory", LoadingElementId = "Loading"  }, new { @class = "button" })

and

 <div id="loanHistory">
    @Html.Partial("_LoanHistory", Model.Loans)
 </div>

When run the Ajax.ActionLink it gets the data back ok and it updates the div, but the url of the sort links on the webgrid then change their address to:

/People/LoanRefresh/AFU0006?sort=CreatedOn&sortdir=ASC

i need to stay as:

/People/Edit/AFU0006?sort=CreatedOn&sortdir=ASC

Any help would be greatly appreciated.


Solution

  • Well @Nick, that's because your action name is LoanRefresh and not Refresh. To do that you will probably have to do some routing or even redirect your LoanRefresh results to an action named Refresh.