I'm assuming this is JavaScript with a server value being written into the output:
// you were missing quotes around the value of "sort"
// (single or double quotes are fine since this is JS)
var sort = "<%= ViewBag.Widget.ToString() %>";
alert(sort);
switch (sort) {
case 'a1':
break;
case 'a2':
break;
case 'a3':
break;
}