Question

I don't exactly understand how ASP.NETs ActionLinks work. I see that they have a event handler for OnSuccess and OnFailure, but I can't find anything that describes how success and failure is determined.

I'm building an ASP.NET MVC application and within it I have a Ajax.ActionLink that allows me to "vote" on items using AJAX...similiar to Digg. The Actionlink kicks off my Controller and method...everything is working fine here.

In my controller I have logic that checks to see if this user has voted before. I wanted to use "OnSuccess" and "OnFailure" to respond differently. I want it to run my Javascript function "PlusOneVote" if the user has never voted (This is the OnSuccess scenario) and if the user has voted before I want run my javascript function "CheaterYouCantVoteTwice".

Can someone explain how OnFailure and OnSuccess are measured?

Can someone explains how I can build this logic...where I can run one Javascript function in one branch (in my case, if the user has never voted) and another Javascript function in the case that the user has already voted?

Was it helpful?

Solution

Success is measured based on the HTTP Status code of the ajax response, and nothing more. Basically if you get a 400 level code (any of 400 - 417), you'll get a failure. If you get a 200, it's considered a success.

I think you'll need to examine the contents of the data in your OnSuccess handler to determine what to do, rather than considering one type a failure message and one type a success message. From the ajax perspective, it was successful if a valid response was returned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top