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 378145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:45:54+00:00 2026-05-12T14:45:54+00:00

I have a view that contains a javascript function that i need to init/call

  • 0

I have a view that contains a javascript function that i need to init/call when the page loads. The method is static but it needs to be called with some parameteres (a list of Id’s) – this list is dynamic and varies by some querystring parameters (i can not generate the list clientside from the querystring).

So i need to generate this list server-side.

My options are, as far as i see it:

1) Make an ajax call on the client, requesting the ids from the server.

2) Inject/inserting the ids directly on the view (it is a property on the viewmodel).

No matter how i turn it, option 2 seems the most sane. I already got the data ready on the viewmodel and thus it’s ready when the view is populated – i see no reason to make an extra request to the server, just to get the data.

I know many would think it’s a bad idea to inject something dynamic into an otherwise static javascript. For that i could simply just inject a new javascript, holding only the Ids and a call to the static javascript method, which is what i really want to do.

My problem is this though: When i write my asp.net <%= %> includes, VS IDE stops highligting, making me think i might be on the wrong track? Surely i’m not the only one needing to output something in a javascript block in asp.net mvc?

  • 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-12T14:45:54+00:00Added an answer on May 12, 2026 at 2:45 pm

    Route 2 (The ViewModel) is definately the way to go and

    <script type="text/javascript>
     <%= Model.JavascriptToInsert %>
    </script>
    

    should work (despite lack of VS highlighting)

    It will NOT work in a seperate JS file though. It must be in your view itself.

    Kindness,

    Dan

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

Sidebar

Ask A Question

Stats

  • Questions 199k
  • Answers 199k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to keep the Group table name you… May 12, 2026 at 7:48 pm
  • Editorial Team
    Editorial Team added an answer You would not be able to do this through a… May 12, 2026 at 7:48 pm
  • Editorial Team
    Editorial Team added an answer You can bind the WrapPanel's MaxWidth to the StackPanel's ActualWidth.… May 12, 2026 at 7:48 pm

Related Questions

Scenario: I have a partial view that is used in several places across my
I have a view using a master page that contains some javascript that needs
Hopefully this example will illustrate my point better than simply trying to explain it:
I have a page which has an Html.DropDownList which takes in a viewdata parameter.
I have a very simple Mac Cocoa app that just has a Web View

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.