Inserting Javascript and HTML from HTMLHelper or from Custom Control In ASP.NET MVC

I was reading this interesting article which increases my ever growing confusion about best practices in MVC link text

and there is a very hot debate about how to fade JavaScript and HTML tags using HTMLHelper or put it in User control.

what do you recommend? in case you are advised to inject it into a custom control, how can you make it generic and use it across different views and keep it testable?

0


a source to share


2 answers


Regarding javascript, I would say that none of the methods work for me. I'm a big fan of unobtrusive javascript , so I always prefer to just add a script tag at the beginning of my page and not write a single line of js in helpers or custom controls.



+4


a source


"Injecting Javascript into Markup" is a bad idea for me. I prefer to separate scripts and markups as much as possible in each specific situation. I am using HtmlHelpers to create custom HTML tags or a set of logically combined HTML tags. With regard to UserControls, I use it mainly to create views that can be returned for an AJAX request and at the same time can be included in "regular pages" (non-AJAX requests).



+1


a source







All Articles