how to get the value of a HiddenFor control in jquery

Rituraj Mishra picture Rituraj Mishra · Feb 25, 2014 · Viewed 17.7k times · Source

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

Answer

David picture David · Feb 25, 2014

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

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

needs to be:

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

?