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

  • Home
  • SEARCH
  • 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 8606267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:02:53+00:00 2026-06-12T03:02:53+00:00

I am trying to get Razor (C#) and javascript to play nicely together but

  • 0

I am trying to get Razor (C#) and javascript to play nicely together but I can’t seem to do it. I have searched the other articles on StackOverflow, but none of them seem
to work for me.

Some noticeable differences from other posts and mine include the following:

I am using an external JavaScript file (not mandatory, but it is there).

I am using a cshtml file for the header layout for all pages (which puts the head tag in a different file than the one actually attempting to call the function.

I also use jQuery, if it would be easier that way.

What I am trying to accomplish:

All I need to do is get the contents of a tag (innerHTML, or .html in jQuery) (by id, class, whatever) and assign that value to “AppState[“gEntryID”] for use with the next page.

Some things I have tried:

function entryClickHandler()
{
    @AppState["gEntryID"] = document.getElementById("tester").innerHTML;
}

AND

function entryClickHandler()
{
    <text>
    @AppState["gEntryID"] = document.getElementById("tester").innerHTML;
    </text>
}

I have tried these (and a few other variations on these) in both the external file and the head section within the HeaderLayout File.

I understand that C# runs before the page and the JavaScript mostly runs after the page (at least with events such as this).

Any help would be greatly appreciated.

  • 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-06-12T03:02:54+00:00Added an answer on June 12, 2026 at 3:02 am

    It doesn’t work that way. You cannot set variables in the C#/Razor side with JavaScript without using a form post or ajax submit.

    Javascript doesn’t get access to the page until after Razor has done it’s part and rendered and sent the page.

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

Sidebar

Related Questions

I'm trying to learn Razor but have come up against a syntax problem. When
I'm new to Umbraco version 5 and Razor , but I'm trying to get
I'm trying to figure out the proper Razor syntax to get a JavaScript file
I am trying to get my razor page to run but I keep getting
Trying to get this expression to work, can someone look at it and tell
I am working on project using MVC 3.0(Razor framework). I am trying to get
Hi am trying get GPS using network provider and GPS provider. but am getting
I'm trying get only the Saturdays and Sundays between two dates, but I don't
My main motivation for trying to do this is to get Javascript that is
Trying to get my ducks in a row with MVC3 + Razor! I finally

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.