Reputation: 101
Why doesn't a basic actionlink allow you to post to a HttpPost method within a controller. It seems odd because you are in affect posting back from a view to a controller.
Upvotes: 0
Views: 358
Reputation: 7514
The ActionLink renders an anchor ( tag) and sets the href attribute to point to a specific controller action. Clicking such a link is not "posting back from a view to a controller" as you state above in your question. Instead the browser performs a GET request. This is standard browser behavior.
It is possible to add a click event handler to an anchor (or any element for that matter) which prevents the default browser behavior. Such an event handler could then perform a POST request in place of the default GET request. This is essentially how ASP.NET WebForms is built. Interactions with HTML elements are intercepted and the __doPostBack method is called which in turn makes a POST request.
So to summarize, the ActionLink method does nothing more than render an anchor DOM element whose default responsibility is to perform a GET request to the href when clicked.
Upvotes: 1