a collection of technical fixes and other randon stuff

Spodworld

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

How to fix SCRIPT1002: Syntax error on an MVC.net form

While developing an MVC view that was taking parameters, i came across this error:


JavaScript critical error at line n, column n in http://localhost/xxxx/xxxx/809273\n\nSCRIPT1002: Syntax error

If you are experiencing a similar issue, it's possible that you are using a viewbag variable to populate a JavaScript variable, or modify some JavaScript code.

For example

var myId = @ViewBag.myViewbagId;

Now if your viewbag value if null (perhaps you don't pass in a parameter any more) ...then this breaks the JavaScript syntax.

Try something similar to the following code to resolve the issue..

var myId = @(ViewBag.MvpForAction==null ?0:ViewBag.MvpForAction);

Add comment

Loading