Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
cshtml error when @model.LocationID is null

In cshtml, I have a @Model EnrollmentModel.

EnrollmentModel has LocationID field.

When I use the statement below, it works when the locationID exists. However, when the locationID is null, it gives an error.

var params = {LocationID : @Model.LocationID};

When I debug the javascript, it just says var params = {LocationID: };

I need a way for cshtml to convert @Model.LocationID to 0 when the value is null.

I also tried using @Model.LocationID ?? 0, but this converts into {blank} ?? 0 in javascript.

Please help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

the easiest way is to add a hidden field

<input type="hidden" value="@Model.LocationID" id="locationId" />

javascript



var params = { LocationID : 0};

var locationId=$("#locaionId").val();

if (locationId > 0) params.LocationID = locationId;
....
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!