I have a scenario where-in I am trying to use the jQuery template plugin for displaying list of data on my MVC list view. However my list is the default view of my mvc application. I want to use the same action to server both purposes of returning json data as well as returning view.
It is making double trip for getting data. Is there a way that as soon as my action is called, I return Json data and use the template plugin to display data.
You can test if the action has been called with AJAX then return JSON data and if not return a normal view:
Of course this
ifmakes your controller action ugly. It would be far better to use action filters to avoid repeating this logic in multiple actions:And then decorate your controller with this attribute: