Html.EditorFor losing value when restarting the page

4

I'm starting my html.editorfor with "0.00" like this:

@Html.EditorFor(model => model.Preco, new { htmlAttributes = new { @Value = "0,00"} })

But when the user receives some validation message (ModelState.IsValid = false), the editorfor loses its value and returns to "0.00". The question is: would I have how do I start the editorfor with "0.00" and after the user type the new value I keep it even if the ModelState.IsValid returns false?

    
asked by anonymous 20.08.2016 / 14:12

1 answer

2

There are several ways to achieve this. Perhaps the simplest is:

@Html.EditorFor(m => m.Preco, new { htmlAttributes = new { Value = Model != null? Model.Preco.ToString("0.00") : "0.00" }})
    
22.08.2016 / 03:21