Thursday, 12 September 2013

Jquery declare int? variable in asp.net mvc4

Jquery declare int? variable in asp.net mvc4

Good day,
I have an asp.net mvc4 project where I tried declare variable in jquery.
Problem to be concluded in next: my data get from the model
@Model.EducationProgramBachelorId and the property
EducationProgramBachelorId in my class declared as int?. And when i try
declare it in my jquery code:
var progId = @Model.EducationProgramBachelorId;
R# told me that int? University.EducationProgramBachelorId Syntax Error
I need this variable in my if/else condition where i want to do next:
if(progId != null){
//Do something
}
else{
//Do something
}
My questions is:
How can I declare int? variable in jquery?
In if statement when it's true I need write just return for that my
function is closed or something else?
EDIT
Here is the part of my RAZOR page:
@model Models.Entities.University
@Html.DropDownList("EducationProgramBachelorId", String.Empty)
@Html.ValidationMessageFor(model =>
model.EducationProgramBachelorId)
<script type="text/jscript">
$(document).ready(function () {
var progId = @Model.EducationProgramBachelorId; //here is I have
an error and function didn't work
if(progId != null){
return;
}
else{
$.getJSON('/Administrator/ProgramList/' + 1, function (data) {
var items = '<option>Select a Program</option>';
$.each(data, function (i, program) {
items += "<option value='" + program.Value + "'>" +
program.Text + "</option>";
});
$('#EducationProgramBachelorId').html(items);
});
}
});
</script>

No comments:

Post a Comment