Search code examples
javascriptjqueryasp.net-mvc-3razor-2

how to get the value of a HiddenFor control in jquery


i have a hidden for control as

@Html.HiddenFor(m => m.SchedulingProfileDetails.Id)

I am trying to access the value in this hidden field in my jquery and then trying to pass the value to controller

  var id = $("#SchedulingProfile_Id").val();

                        $.ajax({
                            url: rootUrl + 'SchedulingProfile/SaveDetails',
                            type: "POST",
                            data: ({
                                schedulingProfileId: schedulingProfileId, 
                                   });

but I am getting null value in id. Please help me out


Solution

  • I could be wrong, but isn't it merely that:

    var id = $("#SchedulingProfile_Id").val();
    

    needs to be:

    var id = $("#SchedulingProfileDetails_Id").val();
    

    ?