Ouput Javascript from C# (ASP.NET 3.5 VS2008)
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 outp开发者_如何学Gouting Javascript but its very messy and I don't think will be maintainable.
Any ideas?
Many thanks
Sam
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.
精彩评论