Reputation: 119
I have defined Latitude and Longitude in my database. Both are Float data type. I want to display the geo information on a map. My problem is when I use @Model (I am using Asp.net MVC and Razor syntax) to pass these information to varables. The code is
var latitude = @Model.Latitude;
var longitude = @Model.Longitude;
It showed me a curly red line behind each line. And when I hovered mouse there, it displayed like
Double?Dinner.Latitude
Double?Dinner.Longitude
I dont have any idea about it. Then I tried to cast the datatype like
var latitude = (double)(@Model.Latitude);
var latitude = (double)(@Model.Longitude);
The red curly line did dispear but it showed me
"Undefined Double"
Who knows why?
Thanks
Upvotes: 1
Views: 962
Reputation: 846
decimal latitude = Convert.ToDecimal(Model.Latitude);
decimal longitude= Convert.ToDecimal(Model.Longitude);
Upvotes: 1
Reputation: 38608
When you are on a razor scope, you do not need to use @
keyworkd to access server-side values. Just try to open a razor block and set the variables, try something this:
@{
var latitude = (double)Model.Latitude;
var longitude= (double)Model.Longitude;
}
And then to show it, use the @
razor keyworkd:
<p>@latitude</p>
<p>@longitude</p>
you also can format this values using ToString()
method from double type:
<p>@latitude.ToString("0.000")</p>
Upvotes: 0