views:

1157

answers:

1

Latest Asp.Net MVC RC permits to return JavaScript ActionResult.
I'd like to dynamically generate from the controller the Jquery script code associated to perform the classical $.ajax calls to the controller for Create Read Update Delete operations in ajax instead of classical get/post form actions. Should I generate the javascript code at design time (like is now with T4 templates) or at runtime?
I know this will break clear separation from view and controller but is there a better way?

+2  A: 

In my opinion this is a bad technique to return javascript action result. You'll receive code mess like when you use inline styles for html elements. Why not to write js in separate file and just include it in page? In order to perform some actions after your ajax call you easily can use a callback. If you need to specify which elements you need to update or delete or something else you can use JsonResult and $.getJSON or $.post(url, data, callback, 'json'). In order to ajaxify your forms you may use jquery.form plugin. Also look at jquery.jframe plugin which provide functionality to update some other elements with a responce from request.

zihotki