I upgraded an MVC3 proj to MVC4 and it appears some javascript functions are not being called after I emit some C# in Razor.
<script type="text/javascript">
$(function () {
var obj = @(Html.Raw(Model.InterestsJson)) ;
alert('This is never called.');
});
</script>
When I extract the emitted string from my Model.interestsJson, javascript functions run normally.
<script type="text/javascript">
$(function () {
var obj = [{ "Id": 1, "Name": "Sports" }, { "Id": 2, "Name": "Entertainment" }];
alert('This will now be called');
});
</script>
What is weird is that this did work up until I upgraded the project to MVC4.
The first thing I did was check for js errors but nothing threw an exception.
Any ideas?
it does not workproblem description. It's so exhaustive. It provides so much details. It's a love. Please go ahead and read sscce.org and ask a real question because I can put the snippet you have shown in a jsfiddle and prove you that it works. The conclusion is that there is something else in your code that you didn't show that's causing the problem. And by mentioning a problem, what is it? Error message? Something? Did you check the FireBug console? Was there something?