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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:18:54+00:00 2026-05-27T23:18:54+00:00

I Have a hidden field that contains a value and my code block within

  • 0

I Have a hidden field that contains a value and my code block within view (within @{} ) requires the same . I have tried a lot of formats trying to use jquery with @: etc. but non of them work.

so basically if i have a hidden field with ID=”aField” having a value, I will require the value of it somehow on to my say a string variable.

@{ string hiddenValue = //Value from that hidden field }

Thanks,
Anand

UPDATE :

The value onto hidden field is populated on some client actions using Jquery and is required before form submit. Hence I am not using view bag . Am i mistaken or missing something ?

hence i am looking for a way to may be if possible use jquery to read back the updated value and use it .

tried a lot to include jquery within the above shown code block to get the value but always end up in errors.

UPDATE 2:

Implemented the suggestion by Shoib (thanks for that) to use Ajax and update the same in viewbag and use it for my requirement, also with break points I see that ViewBag has updated value that I am using in my form.

the next thing i am stumbled up is , on browser still i do not see the value selected . it just displayes old value. Is my update lost during rendering / is it just rendering old HTML ? Any help appreciated

below is my script. server side i just update ViewBAg property with this value that works confirmed.

  function setHiddenFieldValue(buttonEditClicked)
    {



    $('#contactIdHiddenFld').val("");

    $('#contactIdHiddenFld').val(buttonEditClicked.title) ;
    alert($('#contactIdHiddenFld').val());


    $.ajax({         
        url: "@Url.Action("SetPartnerProfileContactID", "PartnerManagement")",         
        data: {partnerContactID: $("#contactIdHiddenFld").val()},         
        dataType: 'html', 
        cache: false,        
        type: "POST",         
        error: function() {             
            alert("An error occurred.");         
        },         
        success: function(result) {             
    jQuery.validator.unobtrusive.parse('EditContactForm');
    Sys.Mvc.FormContext._Application_Load();

          var windowElement = $('#EditContactWindow');         
      windowElement.data('tWindow').center().open();

        }     
    }); 

Also here is a snippet of the form .

@using (Html.BeginForm("GetProfile", "PeopleManagement", FormMethod.Post, new { id = "EditContactForm" }))
{
    <p class="note">
        Please Enter the contact details below</p>


    <table border="0" cellpadding="0" cellspacing="0" id="EditContactsTable">

        @{                
            string toCheck = ViewBag.ContactIDToEdit;
            int count = (from n in Model.PartnerDetails.Contacts where n.PrimaryContactId==toCheck select n).Count();

         }

        <tr>
            <td class="table_label_cell" width="20%" >
                <font color="red">*</font><label for="firstname">@ViewResources.PartnerManagement.GetPartnerProfile.FirstName :</label>
            </td>
            <td class="table_value_cell" width="40%">                   
                @Html.TextBoxFor(m => m.PartnerDetails.Contacts[count].PrimaryContacts.FirstName)

            </td>
            <td class="table_value_cell" width="40%">
                @Html.ValidationMessageFor(e => e.PartnerDetails.Contacts[count].PrimaryContacts.FirstName)
            </td>
        </tr>
        <tr>
            <td class="table_label_cell" width="20%">
                <font color="red">*</font><label for="lastname">@ViewResources.PartnerManagement.GetPartnerProfile.LastName :</label>
            </td>
            <td class="table_value_cell" width="40%">
                 @Html.TextBoxFor(m => m.PartnerDetails.Contacts[count].PrimaryContacts.LastName)
            </td>
            <td class="table_value_cell" width="40%">
                @Html.ValidationMessageFor(e => e.PartnerDetails.Contacts[count].PrimaryContacts.LastName)
            </td>
        </tr>
  • 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-27T23:18:55+00:00Added an answer on May 27, 2026 at 11:18 pm
    public ActionResult Index()
            {
                ViewBag.Message = "Welcome to ASP.NET MVC!";
                ViewBag.hfMyField = Request.Form["hfMyField"];
                return View();
            }
    

    this way you can access it in view.

     <h4>@ViewBag.hfMyField</h4>
    

    for more details on viewbag and other options:
    http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications

    Regards.

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

Sidebar

Related Questions

I have a form with a hidden Came from Adwords field that will be
I have a field in a CCK node form that is hidden, and has
I have an hidden input field with a value, <form> <input type=hidden value=product/> <select
I have a form with a bunch of checkboxes, and a hidden field that
I have a ASP.Net web form that contains both text box fields and hidden
I have a hidden embedded QuickTime object on my page that I'm trying to
I have a hidden input variable called str. I am assigning abc value to
I have a hidden button on a form that I need to click in
I have a form element that contains about 5 fields which final query is
I have a usercontrol that is rendering a list of items. Each row contains

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.