This line is giving me a syntax error in Visual Studio 2012 (literally just 'Syntax Error'):
var data = @Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model));
Model
in this case is the instance of @model MyApp.ViewModels.MyViewModel
declared at the top of my cshtml.
My model is serialized properly into the data var, and the application works correctly. Cosmetically it's just annoying to have the error permanently in my error list.
How should I modify the line so that the compiler is happy?
edit:
As requested, more context. Here's the entire $(document).ready()
:
<script type="text/javascript">
$(document).ready(function () {
$('#ReportDate').datepicker();
$('#DispositionDate').datepicker();
var data = @Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model));
var vm = new NonconformingProductViewModel(data);
ko.applyBindingsWithValidation(vm);
// validate on page load so all reqd fields are highlighted.
var valid = ko.validation.group(vm, {deep: true});
valid.showAllMessages(true);
}); // end document.ready
</script>