I pass model with default values (Id = 0, CityId = null, IsPublished = false) from controller to view:
public class MyModel
{
public int Id { get; set; }
public int? CityId { get; set; }
public bool IsPublished { get; set; }
}
And in view I assign values from model to variables in javascript - cityId should be in javascript type of bool and isPublished should be in javascript null or type of int:
<script>
var cityId = @Model.CityId; // value: False
var isPublished = @Model.IsPublished; // value: ''
</script>
But I have errors:
- For cityId:
Uncaught ReferenceError: False is not defined - For isPublished:
Uncaught SyntaxError: Unexpected token ;
What should I do ?
falseto'False', so you'll have an issue with case sensitivity therevar cityId = @Html.Raw(Json.Encode(Model.CityId))(ditto forIsPublished)boolIsPublished is giving''? And yourintCityId giving 'False' ?