I want to render specific HTML in a partial view based on whether javascript is enabled or not. My idea was to some how detect whether javascript was enabled and store it in a session variable which I can then test for in my view e.g.
<div class="product">
<%
// if Javascript is enabled, load the images asynchrously, otherwise load them directly.
string imgHtml = "<img id=\"myImage\" src=\"{0}\" alt=\"MyImage\" />";
if ((bool)Session["jsEnabled"])
imgHtml = String.Format(imgHtml, Url.Content("~/Content/images/ajax-loader.gif") + "\" onload=\"loadImageAsync(this, '" + Url.Content("~/Content/images/" + Model.thumbnail) + "')");
else
imgHtml = String.Format(imgHtml, Url.Content("~/Content/images/image.jpg"));
%>
<div><%= imgHtml %></div>
</div>
From what I have read most seem to suggest using a hidden field and setting it's value in javascript, however, I don't quite understand how I can get this to work in MVC unless I post the data somewhere (this particular view isn't within a form).