0

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 ?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.