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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:40:39+00:00 2026-05-21T15:40:39+00:00

This is really weird, for some reason the Id of the ViewModel is being

  • 0

This is really weird, for some reason the Id of the ViewModel is being rendered as null inside the view. I debugged the application and checked that the view model is actually being mapped correctly (using AutoMapper) and everything is fine. But when I do @Model.Id, it is rendering as zero, and when I alert the value using jQuery I get “null”. So what’s going on?

            <div id="commentBox">
                @using (Html.BeginForm("Comment", "Item", new { itemId = Model.Id  } ))
                {
                    <span class="greenText">answer</span>
                    <span id="hiddenForId">@this.Hidden(x => x.Id).Id("idPlaceHolder")</span>
                    <span id="commentInputBox">@this.TextBox(x=>x.CommentText).Id("commentField")</span>
                    <span id="commentButton">@this.SubmitButton("").Id("commentSubmit").Class("okButton")</span>
                }
            </div>

        <div style="clear:both"></div>
    </div> 
</div>

<script type="text/javascript">
    $(function () {
        alert($("idPlaceHolder").html());
        $("#commentSubmit").click(function () {
            var dataObj = { 'commentText': $("#commentField").val(), 'itemId': $("idPlaceHolder").html() }
            $.ajax({
                url: '/Item/Comment',
                data: dataObj,
                type: 'POST',
                success: function (result) {
                    if (result.redirectTo != null && result.redirectTo != '') {
                        window.location.href = result.redirectTo;
                    } else {
                        alert(result.error);
                    }
                }
            });
            return false;
        });
    });
</script>

P.S: on a side note, how do you tell the form that it doesn’t need to post and that it has been taken care of? I just cannot remember it… It’s definitely something other than return false;

  • 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-21T15:40:40+00:00Added an answer on May 21, 2026 at 3:40 pm

    Ok I’ve finally figured out what was going wrong:

    $(function () {
        alert($("#idPlaceHolder").val());
        $("#commentSubmit").click(function () {
            var dataObj = { 'commentText': $("#commentField").val(), 'itemId': $("#idPlaceHolder").val() }
    

    I was using $("idPlaceHolder").html() instead of $("#idPlaceHolder").val()… syntax error!

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

Sidebar

Related Questions

A really weird string is being produced inside an array for some reason, and
I tracked down a very weird ... bug... I found that for some reason,
This should be a really simple problem to solve, but for some reason Entity
This is really weird, and I cannot see why this is happening. In the
Well this is a really weird issue, I really didn't find anything on this
After ages of programming in php this question seems really weird still to me.
Boy, this one is really weird. I expect the following code to print 1990,
Ok, this one is really weird... I can't show code for it exactly cause
Ok, this is a really weird one. I have an MPI program, where each
A really weird thing happens in this code JNIEXPORT jintArray JNICALL Java_jsdr_SdrLibrary_getTunerGains (JNIEnv *

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.