Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3789862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:13:28+00:00 2026-05-19T12:13:28+00:00

I have a Javascript statement in an MVC view that looks like this and

  • 0

I have a Javascript statement in an MVC view that looks like this and works:

win.attachURL('<%: Url.Action("GraphDetails", "Dashboard", new { area = "Anglian", OSName = "Hello" }) %>');

When I try to extract the variable ‘Hello’ and put it into a javascript variable (id) and subsequently embed it into my tag like this, it breaks:

var id = "Hello";
win.attachURL('<%: Url.Action("GraphDetails", "Dashboard", new { area = "Anglian", OSName = "' + id + '" }) %>');

Question is, how do I embed a JS variable inside an ASP server tag, that itself is already embedded within Javascript? This is for a local prototype, security concerns are not an issue.

Thank you,

Tom.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:13:29+00:00Added an answer on May 19, 2026 at 12:13 pm

    I don’t think you can in general. In this case at least the <%: … %> part is evaluated at page load time and will never run again.

    Instead, you can compute this in JavaScript, e.g.

    var id = "Hello";
    var baseURL = '<%: Url.Action("GraphDetails", "Dashboard",
                                  new { area = "Anglian" }) %>';
    win.attachURL(baseURL + '&OSName=' + id);
    

    However that makes assumptions about how you’re assembling your routing parameters for that route. You could use Url.Action to generate the full route with a dummy value and then substitute, e.g.

    var id = "Hello";
    var baseURL = '<%: Url.Action("GraphDetails", "Dashboard",
                                  new { area = "Anglian", OSName="ZZZ" }) %>';
    win.attachURL(baseURL.replace('ZZZ', id);
    

    but then there’s a subtle chance this could go wrong, particularly if you’re feeding user generated string into other parameters in the string where they could hit on the value you substitute.

    If you really did want to run Url.Action again you’d have to make an AJAX call back to a known URL with the parameters to get the URL, which is overkill really.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have a simple if statement in my view that returns x = 0
I have a JavaScript method that I need to run on one of my
I have a javascript function that manipulates the DOM when it is called (adds
I have a JavaScript resource that has the possibility of being edited at any
I have a JavaScript snippet that runs very well on Firefox and Safari, but
I have a JavaScript function, pop_item . I have to call this from PHP,
I have a JavaScript class that I have made and put it into its
I have a javascript routine that is performing actions on a group of checkboxes,
In my javascript I have this loopDeLoop: while (foo !== bar) { switch (fubar)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.