I have a field for weight in Kgs (type double or use something else??). In edit view I would like the user to enter numbers to the thousandth place<
To format the number just use
@string.Format("{0:0.00}", Model.Weight);
or
@Html.DisplayFor(x => string.Format("{0:0.00}", x.Weight));
@Html.EditorFor(x => string.Format("{0:0.00}", x.Weight));
to Validate
public class Model
{
[Required]
public double Weight{ get; set; }
}
I wouldn't constrain the precision they put in, just make sure that it is a valid number using javascript. You might also constrain input to only include numbers and a period.
If the user puts in something wrong (i.e. not compatible with a double type), MVC will complain when it tries to bind to the model.