1

I have the next model:

 public class MyModel
{
    [Display(Name = "My Date:")]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")]
    public System.DateTime Date { get; set; }
}

than I display it with the editing part:

@using (Html.BeginForm()){

@Html.DisplayFor(x=>x.Date)
@Html.EditorFor(x=>x.Date)
@Html.ValidationMessageFor(x=>x.Date)
<input type="submit" value="ok"/>}

I recive the model in my controllers

 public ActionResult Index()
    {
        ViewBag.Message = "Welcome to ASP.NET MVC!";
        var model = new MyModel {Date = DateTime.Now.AddDays(-1)};
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(MyModel model)
    {
        if (ModelState.IsValid)
        {
            return View(model);

        }
        return View(model);
    }

It shows enter image description here My local machine format is (mm/dd/yyyy) and when I try to submit this form I have the wrong validation: enter image description here I read that some people advice to write my own binding or my validator. The question is why I have to do it while I set ApplyFormatInEditMode = true. Does it means that this attribute is not working!!!!

user1706449
  • 159
  • 1
  • 1
  • 9

0 Answers0