what is the alternative of using url.action in ajax

Amgad Mohamed picture Amgad Mohamed · Apr 4, 2016 · Viewed 7.3k times · Source

E.g.

@url.Action("Actionname", "ControllerName", new { [email protected], @class="test"})

I want such a thing in Ajax, like this:

@Ajax.action("Actionname", "ControllerName",new { [email protected], @class="test"})

I tried this, but it did not benefit me:

  @Ajax.ActionLink(".", "DeleteCountry", "Main", new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "Details" }, new { CountryID =  item.CountryID , @class="fa fa-times"}) @Ajax.ActionLink(".", "EditCountry", "Main", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "Details" }, new {CountryID=item.CountryID,@class="fa fa-pencil"})

Can anyone assist me with this?

Answer

Xavr picture Xavr · Jul 26, 2016

In asp.net mvc I use both Ajax.BeginForm

 @Ajax.BeginForm("Action", "Controller", new AjaxOptions { HttpMethod = "POST",        OnSuccess = "successFunction", ... })
{
    @Html.HiddenFor(item => item.id)
    //etc fields you want to send
}

and JQuery ajax

$.ajax({
url: '@Url.Action("Action", "Controller")',
        type: "GET",
data: { 'id': '@item.id' },
        success: ... 

});

Think it will help you.