Home Dashboard Directory Help
Search

Valid javascript/Razor syntax marked as syntax error by notken_uk


Status: 

Closed
 as Deferred Help for as Deferred


52
0
Sign in
to vote
Type: Bug
ID: 760339
Opened: 8/30/2012 2:34:22 AM
Access Restriction: Public
1
Workaround(s)
view
17
User(s) can reproduce this bug

Description

When attempting to output json to a view in javascript, it's marked as being a syntax error despite being valid. If I surround with quotes or square brackets it's fine, but that's not what I need to do!

eg,
[Javascript function inside script tag]
var existing = @(Model.ToMvcHtmlStringJson());

Red-underlining of the last semi-colon, marked as syntax error, and view won't compile.

This wasn't an issue in VS 20120
Details
Sign in to post a comment.
Posted by Sumiflow on 3/5/2014 at 9:22 AM
This still hasn't been fixed even in visual studio 2013. What's the deal?
Posted by Ken Smith on 8/20/2013 at 12:04 PM
Any update, guys? It's been a year now.

I love Visual Studio, but it's when bugs like this go unfixed for so long that I start dreaming about how cool it would be to work on an open source stack...
Posted by Sachelis on 8/1/2013 at 10:51 AM
I'm experiencing the same problem in VS2012. In my case, I can assign the ASP value to a variable and use it in the javascript.

This works:

    var proposalCount = @(Model.Proposals.Count())
    $("#ProposalsHeading").text(" (" + proposalCount + ")");

Whereas this next code displays a syntax error on the ";". Note that for me, it'll still compile and run, but the trailing ")" isn't displayed:

    $("#ProposalsHeading").text( " (" + @(Model.Proposals.Count() + ")");

Posted by PRISMAY on 7/3/2013 at 6:38 AM
Is there an update on this issue? I just installed Update 3 and this has NOT been fixed. What's the hold up? Thanks.
Posted by Microsoft on 10/25/2012 at 2:34 PM
Thank you for passing along this issue to us. At this point, we are pulling together this and other feedback as part of our planning and evaluation for the next release. We know that our customers are the most qualified people to help us learn how to make our products better, and we greatly appreciate hearing from you.
Posted by 2Mode on 10/16/2012 at 8:21 AM
I entered a StackOverflow page at:
http://stackoverflow.com/questions/12275095/upgrade-from-net-4-to-4-5-breaks-html-raw-call-in-javascript

To reproduce at the following to a razor page

@{
    var listData = "test";
    var pagerData = "test2";
}
    <script type="text/javascript" >
        var ListData = @(Html.Raw(listData))
        var PagerData = @(Html.Raw(pagerData))
    </script>

If you add a semi-colon at the end of the ListData line you get a javascript syntax error, without one it is on the next line. This a bug in the javascript compiler between VS2010 and VS2012.

WillC
Posted by Microsoft on 8/30/2012 at 7:26 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Microsoft Visual Studio Connect Support Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 8/30/2012 at 2:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Ken Smith on 8/20/2013 at 12:03 PM
The best workaround I've seen for this is to wrap the @ reference in an array, and then select the first element of the array. For instance:

var campaignId = [@Model.CampaignId][0];

Of course, wrapping it in quotation marks sorta works too, but then it transforms it into a string, which may not be the desired behavior:

var campaignId = "@Model.CampaignId";

Still, really darned annoying that we're at Release 3 of VS2012 and MS hasn't fixed it.
File Name Submitted By Submitted On File Size  
SolutionFingerprint.5356.html (restricted) 8/30/2012 -
UploadSummary-120830093416.xml (restricted) 8/30/2012 -
VsInfo.xml (restricted) 8/30/2012 -
SolutionFingerprint.11672.html (restricted) 8/30/2012 -
DxDiagOutput.txt (restricted) 8/30/2012 -
ScreenShot.jpg (restricted) 8/30/2012 -
SolutionFingerprint.11540.html (restricted) 8/30/2012 -