I prefer to use jQuery with my ASP.NET MVC apps than the Microsoft Ajax library. I have been adding a parameter called ‘mode’ to my actions, which I set in my ajax calls. If it is provided, I return a JsonViewResult. If it isn’t supplied, I assume it was a standard Http post and I return a ViewResult.
I’d like to be able to use something similar to the IsMvcAjaxRequest in my controllers when using jQuery so I could eliminate the extra parameter in my Actions.
Is there anything out there that would provide this capability within my controllers or some simple way to accomplish it? I don’t want to go crazy writing code since adding a single parameter works, it just isn’t ideal.
Here’s an except from MVC RC1 release notes – Jan 2009
IsMvcAjaxRequest Renamed to IsAjaxRequest
In other words – it was specifically renamed to be more ‘compatible’ with other libraries.
In addition, for anyone who hasnt read the full release notes but has been using previous versions – even as recent as the beta – I STRONGLY recommend you read them in full. It will save you time in future and most likely excite you with some of the new features. Its quite surprising how much new stuff is in there.
Important note: You will need to make sure you upgrade the .js file for MicrosoftAjax.MVC (not the exact name) if upgrading to RC1 from the Beta – otherwise this method won’t work. It isn’t listed in the release notes as a required task for upgrading so don’t forget to.