This works great for me :)
Here is what I used as an 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 my index.cshtml I call it like this:
@using MvcApplication1.ExtensionMethods .... @Html.SomeJavascript()
and it shows me a popup :)
Alex peta
source share