DevMania
DevMania

Reputation: 2341

Injecting Javascript and HTML from HTMLHelper or From User control IN ASP.NET MVC

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 ?

Upvotes: 0

Views: 994

Answers (2)

eu-ge-ne
eu-ge-ne

Reputation: 28153

"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).

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

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.

Upvotes: 4

Related Questions