Search code examples
jqueryajaxumbraco

get variable from umbraco form using jquery


I have a jquery that I need to get a variable decleared inside the form

currently jquery line is

$.ajax {
    var GId = $('#globalSettingsId').val();
..... Rest of script 
}

the globalSettingsId is deleared in the umbraco form first couple of lines

@{
    int globalSettingsId = Convert.ToInt32(ViewData["globalSettingsID"]);

...... Form layout Code .....
}

the script fails to run as is


Solution

  • Solved

    Need to have an Html representation of the variable.

    @Html.Hidden("globalSettingsId", globalSettingsId)