When I send the form from client side I can see that Nap.GetUp has a value. However when debugging I see that the controller has not gotten a value for Nap.GetUp. I don't know where the error lies or how to find it...
This problem arises when I format the value of my input field(for editing my form). Since my database uses "," for punctuation while my input (type="number" step="0.1
) in the view requires "." punctuation in order input the value to field. I solve this this way:
@{
string getUpValue = (Model == null) ? null : Model.GetUp.ToString().Replace(",", ".");
}
@Html.LabelFor(m => m.GetUp, new { @class = "" })
@Html.TextBoxFor(m => m.GetUp, new { @type = "number", @step = "0.1", @Value = getUpValue, @class = "form-control" })
If I remove Value = getUpValue,
in the TextBox there is no problem in saving the value to the database, but the value will not load into the field when editing the form later on...
--- Edit ---
Model:
public class Nap
{
public int Id { get; set; }
public Period Period { get; set; }
public int PeriodId { get; set; }
[Required]
[Display(Name = "Start")]
public DateTime Start { get; set; }
[Required]
[Display(Name = "Slutt")]
public DateTime End { get; set; }
[Display(Name = "Sovne")]
public int? FallAsleep { get; set; }
[Display(Name = "Våkne")]
public double? GetUp { get; set; }
...
Controller:
public ActionResult Edit(int id)
{
var nap = _context.Naps.Single(m => m.Id == id);
if (nap == null)
return HttpNotFound();
return View("NapForm", nap);
}