Razor/JavaScript and trailing semicolon

前端 未结 7 1030
不知归路
不知归路 2020-12-01 11:30

Using Visual Studio 2012, on a Razor view page, in the JavaScript section, I am getting what I think is a battle between Razor syntax vs JavaScript syntax. In particular, th

7条回答
  •  心在旅途
    2020-12-01 12:20

    Since this still seems to be happening and it is a nuisance I figured I will at least let others know what I ended up using as a "hack". I don't want to ignore the warning and would rather accept a hokier syntax (and yes someone is going to say this will kill performance :))

    What I use as a workaround is to use a client side addition at the end. For me this error occurred on defining an "integer" constant, so

    window.foo = @(Model.Something);
    

    gave me the good old semicolon error. I simply changed this to:

    window.foo = @Model.Something + 0;
    

    (In the stated questions case you should just be able to add '', so + ''.

    I know there is a whole another addition happening on the client and it isn't elegant, but it does avoid the error. So use it or don't, but I prefer this over seeing the warning/error.

    If someone knows of a server-side syntactical workaround for this I would prefer this to the client-side one, so please add.

提交回复
热议问题