public virtual void Render(ViewContext viewContext, System.IO.TextWriter writer) { // We'll be writing out javascript viewContext.HttpContext.Response.ContentType = "text/javascript"; // Wrap the code in a try/catch just to signal errors writer.WriteLine("try {"); // Have the derived view render it's script into the context // then render it to the output stream var ctx = new CsJsViewContext(viewContext); Render(ctx); writer.Write(ctx.GetScript()); // Close the script try/catch writer.Write("} catch(error) { alert('csjs error'); }"); }