So this is what happens.
I'm pulling data from db to show it on application.
I save it to ViewModel and all data is there, so no problems with queries or anything backend-wise.
So I used html helper to show data.
@Model.SelectedVehicle.VehicleId
When I wrote it out on HTML, it was okay as you can see here.
http://imgur.com/7uZbAnr
But problem starts when I write it out using JS (alert or console.log), cuz it somehow or somewhat changes value of data as you can see here.
http://imgur.com/bFA9E6I
On console log screen show 12 is VehicleId which is supposed to be 0014 as you could see on HTML screenshot, where 1234 is DriverId and I have no issues displaying it either way.
I have no idea how or why this is happening, so if someone could explain me what might be causing it, I'd be grateful.
What I have tried:
I tried figuring it out by myself but I cannot solve it, cause that number 12 is nowhere is db.
On other vehicle where Id is 0000, JS writes out 0.
EDIT:
Controller:
[HttpPost]
[Authorize]
public ActionResult SelectedVehicle(DashboardViewModel model)
{
var userId = User.Identity.GetUserId();
var currentDriver = context.Drivers
.Where(m => m.AccountId == userId && m.DriverId == model.DriverId)
.Select(c => c)
.FirstOrDefault();
var currentVehicle = context.Vehicles
.Where(m => m.AccountId == userId && m.VehicleId == model.VehicleId)
.Select(c => c)
.FirstOrDefault();
var viewModel = new DashboardViewModel
{
currDriver = currentDriver,
currVehicle = currentVehicle
};
return View("Index", viewModel);
}
ViewModel:
public class DashboardViewModel
{
public DashboardViewModel()
{
this.currDriver = new Driver();
this.currVehicle = new Vehicle();
}
public Driver currDriver { get; set; }
public Vehicle currVehicle { get; set; }
}
HTML part which works normal:
<div class="x_content">
Being tracked now:
"vehicle-name">@Model.currVehicle.RegistrationPlates
driven by
^__strong id="driver-name">@Model.currDriver.Firstname @Model.currDriver.Lastname
</div>
JS part:
<script>
$('a.pick-this').on('click', function () {
console.log(@Model.currVehicle.VehicleId);
console.log(@Model.currDriver.DriverId);
});
</script>
HTML SOURCE:
<div class="x_content">
Being tracked now:
"vehicle-name">222-B-222
driven by
^__strong id="driver-name">Faris Karcic
</div>
JS SOURCE:
<script>
$('a.pick-this').on('click', function () {
console.log(0014);
console.log(1234);
});
</script>
As I have noticed now, values in JS are right, but why I'm getting in console instead of 0014 number 12 still?
I just wanna learn why this happens...