How to get the value of a HiddenFor element in jquery

I have a hidden control like

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

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

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

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

but I get null in id. Please help me

+3
source share
2 answers

I could be wrong, but isn't it easy:

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

should be:

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

?

+11
source

It’s always good for me to check the generated HTML page, just look for hidden input.

Also you are trying to pass schedulingProfileId to your AJAX call, I think it should be:

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

All Articles