I just upgraded an ASP.NET MVC app to version 3.0 and Razor.
I have the following code in my home page:
<script type="text/javascript">
/*@cc_on@*/
var LastUserSetting = @Html.Raw(Json.Encode(ViewData["LastUserSetting"] == "" ? "''" : ViewData["LastUserSetting"]));
</script>
In the browser, this ends up showing as:
var LastUserSetting = @Html.Raw(Json.Encode(ViewData["LastUserSetting"] == "" ? "''" : ViewData["LastUserSetting"]));
With the following error message: “reference to undefined XML name @Html”
which is obviously not what I intended.
What Am I missing? What did I do wrong?
Many thanks!
You are using Razor code inside a WebForms master page. That does not work. Razor syntax only works in Razor views (cshtml or vbhtml)
So you need to switch back to using the WebForms syntax in that master, or switch to using actual Razor views.