Search code examples
ajaxurlasp.net-mvc-ajax

what is the alternative of using url.action in ajax


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?


Solution

  • 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.