Results 1 to 2 of 2

Thread: [RESOLVED] obtaining hidden values in JQuery

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Resolved [RESOLVED] obtaining hidden values in JQuery

    Hi All,

    In my MVC Project I have a couple of Hidden values in the Form

    Code:
    @Html.Hidden("policyZoneID", ViewData["policyZoneID"])
    Now in my Script I currently Have:

    Code:
    var jSonData = '{ "available" : "  ' + availableArray +
                              '", "unavailable" : " ' + assignedArray + '"}';
    
                $.ajax({
                    type: 'POST',
                    url: '/PolicyZone/JsonEditFloatingZone',
                    data: jSonData,
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (response)....
    I want to grab the hidden values and attach them to my jSonData variable to pass to my controller.

    Also as an aside, is there an easy way to pass the Model in this context?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Re: obtaining hidden values in JQuery

    In your json data, you don't have to use single quotes for string variables, jquery will take care of that for you.
    Code:
    var hidValue = $("#policyZoneID").val();
    
    
    $.ajax({
                    type: 'POST',
                    url: '/PolicyZone/JsonEditFloatingZone',
                    data: 
                    {available: availableArray, unavailable: assignedArray, hiddenValueParameter:  hidValue },
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (response)....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width