0

I'm trying to output Javascript from a C# ASP.NET MVC 2 website.

Basically, I'm creating a widget that people can add their website (by just adding a script tag which gets its code from an MVC action on my website.)

The reason for this is I want the users to be able to configure the output of the script via my website.

(colours of injected DOM elements, position of the widget on screen [Top left, Bottom right etc])

I've looked at script# but it looks a bit overkill. I've started using StringBuilders and outputing Javascript but its very messy and I don't think will be maintainable.

Any ideas?

Many thanks

Sam

1 Answer 1

1

The way I approached this was to make template scripts (text files) that are embedded resources in the assembly. Then it's a simple matter of pulling out the resource and replacing tagged fields in the templates with the relevant values. Works quite nicely and the template files are easy to edit, but you need to validate and/or escape the values going into the template if they are supplied by the client in order to avoid breaking the generated JS (and potentially introducing a security hazard). There's no reason why they couldn't be loaded from disk, and it's probably an excellent candidate to go into the HttpRuntime cache.

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

1 Comment

like an email template. That's a really good idea! Thanks for that never would of thought of doing that. Will have a play and get back should I need any more help.

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.