1

I have a code block in some JavaScript on a razor page. Just before the code block I have a normal JavaScript variable. How do I access this variable from withing the Code Block?

CodeBlock

1
  • 4
    Hi there. It would be preferable to paste your code as text. That way your post will be smaller on the SO servers and it will be searchable. Thanks. Commented Apr 16, 2014 at 7:10

1 Answer 1

1

I belive you could use @:

Something like this:

if(context.Project.Find("ProjectId"){
     @:actionToTake = "ProjectOutcome";
}

or the special text-tag

if(context.Project.Find("ProjectId"){
     <text>actionToTake = "ProjectOutcome";</text>
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, how about in the following: $("#next-step").click(function () { document.location.href = "@Url.Action("Read", actionToTake, new { ProjectId = ViewContext.RouteData.Values["ProjectId"] }, null)"; });
I would put the url in a separate variable outside the click-function. Then insert it as the href with @variablename
Yes, should have thought of that sooner. That negates the need for the actionToTake in the first place

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.