farhang67 farhang67 - 1 year ago 69
Javascript Question

Asp.net razor javascript avoid doing math on string

I have a model:

public class VisitsTimelineModel
public string Time { get; set; }

public int Count { get; set; }


I fill and pass this model as viewbag to my view:

VisitsTimelineModel VisitsTimelineModel = new VisitsTimelineModel();
VisitsTimelineModel.Count = 10;
isitsTimelineModel.Time = "2/3";

then in my view in javascript section if I use below code:


it will alert 0.666666 but I want output to be 3/2.

Ted Ted
Answer Source

You're missing the quotes in the alert statement.


I've also removed the unnecessary brackets and .toString() call.