1

I have an annoying issue that I'd like to resolve. On my page, I have some Javascript that I need for sending/receiving messages through SignalR. THat page works just like it should, but in the VS2012 IDE I always get a warning about a Syntax Error in the code. This is the code in my View:

$(function () 
    {
        var usr = $.connection.paMessageHub;

        // I cut out the inner code of the following function
        $.connection.hub.start().done(function () { });  

        function sendValue = function (StationId, DataPointId, Value) 
        {
            usr.server.sendValue(StationId, DataPointId, Value);
        };

        usr.client.updateValue = function (StationId, DataPointId, NewValue)
        {
            if (StationId == @ViewBag.StationId )
            {
                updateValues(StationId, DataPointId, NewValue);
            }

    };

I know there's obviously missing a closing curly bracket in the second last line, but the code just runs perfectly when it is exactly like that. The syntax highlighting says Syntax Error on the closing bracket of

if (StationId == @ViewBag.StationId )

and also says "')' expected" on the semicolon in the line

updateValues(StationId, DataPointId, NewValue);

Is this a bug or am I missing something important? When I insert a closing curled bracket in the second last, the script does not work any more. Thanks for your help!

Update: this simplified example shows the same error:

if ( 1 == @ViewBag.StationId )
{
    alert("Test!");
}
1
  • Try this - if(StationId.toString()[email protected]) Commented Jun 27, 2013 at 13:20

1 Answer 1

1

Sometime razor gets a little confused when you mix C# and JavaScript. Read this post It will resolve or your doubts (it did for me) about why razor "gets confused" http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.