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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:27:58+00:00 2026-06-02T16:27:58+00:00

I am having a fat headache session with this following code, and was wondering

  • 0

I am having a fat headache session with this following code, and was wondering if anyone can help me.

I have a view called Details.aspx, residing in a folder called project. Inside the details view, I have the following key code snippets which is causing me to get a headache.

<script type="text/javascript">
var Global_ProjectID = <%:Model.ProjectID%>; //Gets the project ID from Project Table In model
</script>

Inside a form tag (<form action="<%: ResolveUrl("~/Issue/AddIssue") %>" method="post">) resides the following code:

        <p>
            <input type="submit" class="submit small" value="Add Issue" onclick="return IssueSubmitForm()"/>
            or <a href="">cancel</a></p>

And then I have some more Javascript to talk to my controller called IssueController, with the method called AddIssue

<script type="text/javascript">
    var PostBackUrl = "<%:ResolveUrl("~/Issue/AddIssue")%>";

    //Front-end Validation here

    function IssueSubmitForm() {
        var PostBackData = {
            Title: $("input[name=Title]").val(),
            Details: $("textarea[name=Details]").val(),
            ReportedBy: $("input[name=ReportedBy]").val(),
            Priority: $("select[name=Priority]").val(),
            ProjectID: Global_ProjectID
        };

        $.post(PostBackUrl,PostBackData);
    }
</script>

This gets the information entered into the form (from various web controls), and the value from the Global_ProjectID

In my controller, the following method is the one that is called from my javascript

    [HttpPost]
    public ActionResult AddIssue(Models.Issue issue)
    {
        Models.Issue newIssue = new Models.Issue()
        {
            Title = issue.Title,
            DateLogged = DateTime.Now,
            Status = 0,
            ReportedBy = issue.ReportedBy,
            Priority = issue.Priority,
            ProjectID = issue.ProjectID,
        };
        return View("SomeOtherViewSomewhere");
    }

Now here is the weird part.

All my fields (like title, reportedby etc.) gets filled as it should, i.e. It actually contains the value I expect it to contain- the data I filled into my form. ProjectID always happens to be null, when it should actually contain an integer value.

When I activated the debugger on my javascript in my browser, I saw that ProjectID did get populated, and in the event I added the following code Alert(Global_ProjectID);, it also gave me a popup with the value I needed.

However, the moment I run these code segments without debugging, ProjectID is always null. It is sadly a value that I must use recurringly, and null simply won’t do

What can I do to fix this code? I had other programmers look at it, and they were also just as stumped as I were.

  • 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-02T16:28:00+00:00Added an answer on June 2, 2026 at 4:28 pm

    I’d suggest looking into Javascript Scoping and Hoisting – JS doesn’t always behave in the way you expect with regard to the order in which variables and functions are initialised.

    You can probably work around the issue by adjusting your IssueSubmitForm function to accept ProjectID as a parameter, and use onclick="return IssueSubmitForm(Global_ProjectID)" on your submit button…

    Or even better, remove the inline function call and bind a submit event after the page has loaded in the $(document).ready() event.

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

Sidebar

Related Questions

Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
Having the following code: template<typename T, typename OutStream = std::ostream> struct print { OutStream
Outline OK, I have Google'd this and already expecting a big fat NO!! But
Having a problem with the following Query. i have a device table which logs
Having a spot of trouble with the following code. The method NextIPID() should simply
Having already read a number of articles on this here is the code I've
Does anyone (here) know if Windows 8 will have a sort of fat exe
Having a lot of pain with the following Perl file parsing code [last reply
Having another issue, and this one is BAFFLING! Here we go. We have a
Having a bit of an issue please see the following code: window.onload = function

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.