Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax.ActionLink vs Html.ActionLink + Jquery.Ajax call

I can call an asp.net mvc controller via Ajax.ActionLink("Get customers","GetCustomers","Customer");

I can do the same with the Html.ActionLink and a jquery ajax call.

Where is the difference?

like image 342
Pascal Avatar asked Apr 23 '12 08:04

Pascal


People also ask

What is difference between HTML ActionLink and url action?

There is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.

What is HTML ActionLink ()?

ActionLink(HtmlHelper, String, String, String, String, String, String, Object, Object) Returns an anchor element (a element) for the specified link text, action, controller, protocol, host name, URL fragment, route values, and HTML attributes.

How can we call post method using ActionLink in MVC?

ActionLink is rendered as an HTML Anchor Tag (HyperLink) and hence it produces a GET request to the Controller's Action method which cannot be used to submit (post) Form in ASP.Net MVC 5 Razor. Hence in order to submit (post) Form using @Html. ActionLink, a jQuery Click event handler is assigned and when the @Html.

How can we navigate from one view to another in MVC?

In Mobile JS, you can transfer from one view to another view by using App. transferPage method. To achieve this, set the page url '/controllername/viewname' (here it's given as /Home/Ajax) as the second parameter of App.


1 Answers

Where is the difference?

In the amount of code you have to write (less with Ajax.ActionLink) and the level of control you need (more with Html.ActionLink and a jquery ajax call).

So it's amount of code vs level of control and functionality needed => up to you to decide which one you need.

Both approaches are perfectly fine. The Ajax.ActionLink uses the jquery.unobtrisuve-ajax script to AJAXify the anchor behind the scenes.

Personally I always use Html.ActionLink + jQuery.

like image 148
Darin Dimitrov Avatar answered Sep 23 '22 21:09

Darin Dimitrov