tags:

views:

136

answers:

2

hi, i have been reading this interesting article which is increasing my every growing confusion about best practices in MVC link text

and there is a very hot debate about wither to inject JavaScript and HTML Tags using an HTMLHelper or putting it in User control.

what do you advise ? in case you advise putting it in user Control, how can you make it generic and use it in different views and keep testability ?

thanks in advanced.

+3  A: 

Concerning javascript I would say that none of the methods seems suitable for me. I am a big fan of unobtrusive javascript, so I always prefer just adding a script tag in the beginning of my page and not writing a single line of js in helpers or user controls.

Darin Dimitrov
great advise, thanks alot
+1  A: 

"Injecting Javascript into markup" is bad idea for me. I prefere to separate scripts and markup as much as it possible in every concrete situation. I'm using HtmlHelpers for creating custom HTML tags or set of logically combined HTML tags. As for UserControls I'm using it primarily for creating Views, which can be returned for AJAX request and at the same time could be included into "normal page" (non-AJAX requests).

eu-ge-ne