asp.net mvc - Rendering Javascript via custom HTML Helper extension method? -
in our asp.net mvc3 project have written couple of custom html helper extension method, renders composit controls (say text , label needed styles). want render javascript along html tags, looks mvchtmlstring not render javascript test javascript ! options or alternatives render dynamic javascript custom html helpers ?
it works fine me :)
here used extension method:
namespace mvcapplication1.extensionmethods { public static class myextensionmethods { public static mvchtmlstring somejavascript(this htmlhelper helper) { stringbuilder sb = new stringbuilder(); sb.append("<script> alert('testing 123')</script>"); return mvchtmlstring.create(sb.tostring()); } } } and in index.cshtml call this:
@using mvcapplication1.extensionmethods .... @html.somejavascript() and shows me pop-up :)
Comments
Post a Comment