javascript - Why can't I get my DropDownList change event work? -


i'm trying make simple dropdownlist (something simple , fun in c# somehow frustrating in context) allow me navigate around mvc app.

i'm not experienced javascript @ all, i've spent of day trying sorts of things , using chrome's javascript console try , troubleshoot can.

this i've boiled down to.

razor engine view:

<h2>index</h2>  <p>    @html.dropdownlist("ddlregion", new selectlist(viewbag.tables), new { @id  = "ddlregion" }) <br />    @html.actionlink("area1", "index", "area1") <br />    @html.actionlink("area2", "index", "area2") <br />    @html.actionlink("area3", "index", "area3") <br /> </p>  @section scripts{  <script src="/scripts/jquery-1.10.2.js" type="text/javascript"></script>  <script type="text/javascript">      $("#ddlregion").change(function () {          var selecteditem = $(this).val();           switch (selecteditem) {             case '0':                window.location.href = @url.action("index", "area1");                break;             case '1' :                window.location.href = @url.action("index", "area2");                break;             case '2' :                window.location.href = @url.action("index", "area3");                break;             default:                window.location.href = @url.action("index", "area1");                alert("blarg");                break;          }       });   </script> } 

the latest error javascript console complaining missing / on case '0' block @url.action method (translates end '/area1').

window.location.href = @url.action("index", "area1"); rendered window.location.href=siteprefix/area1/index;

now, window.location.href=siteprefix/area1/index; not valid javascript statement. rhs of expression should proper value. since url, can treat string.

window.location.href = '@url.action("index", "area1")'; appending single quotes around rhs work.