Clean blend of javascript and csharp

, , 1 Comment »

Just came across this code which I thought looked remarkably clean, considering how bad this type of thing could normally turn out.

This is including a small inline javascript at the tail of the layout. A dictionary in viewdata contains any number of key/value pairs that are passed to Omniture.

<viewdata OmnitureValues="Dictionary[[string, object]]"/>
<script type="text/javascript" language="JavaScript" src="http://www.example.com/include/js/s_code.js"></script>
<script type="text/javascript" language="JavaScript">
if (typeof s != "undefined")
{
# if (OmnitureValues != null)
# {
#   foreach (var val in OmnitureValues)
#   {
      s.${H(val.Key.ToLowerInvariant())} = "${H(val.Value)}";
#   }
# }

/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code) }//
</script>

The lines starting with hash (#) marks are server-side code. The innermost line ends up being written out in the script once for each key/value pair. The thing I thought was so striking was how I scanned and grokked what the function was doing before I even realized I was looking at a mix of inline javascript and csharp.

So good job to the programmer that did this one. :)

Returning PDFs from an ASP.NET MVC action

, , , , , 10 Comments »

This feature is based on a post from Bill Barry, “Using Spark to render PDFs,” to the Spark discussion group.

It’s based on iTextSharp, a port of the iText Java PDF library. It seemed like such a useful twist on the view engine, and so applicable to web sites, that I integrated what Bill had done into the Spark project and added a PdfViewResult action result for the ASP.NET MVC library.
Read the rest of this entry »

Design by j david macor.com.Original WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in