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?
There is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With