0

I am facing an issue when editing an existing instance of my model Client:

public class Client{
    public int ClientID{get;set;}
    [DataType(DataType.Date)]
    public DateTime dateIn{get;set;}
}

My controller:

[HttpPost]
public ActionResult EditFC(Client client, Connexion connexion)
{
        if (ModelState.IsValid)
        {                
            db.Entry(client).State = EntityState.Modified;
            var t = client.dateIn;

            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(client);
}

The error that is thrown is:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

So I don't know what's it happening my variable is dateTime I display it as a Date and I think it is maybe the problem that is when editing it takes a Date and not a DateTime, maybe I have to do a conversion but I don't how ?

4
  • What's the value of t when you look at it using a debugger? Commented Sep 24, 2014 at 7:53
  • Have you seen this question? Commented Sep 24, 2014 at 7:57
  • Where exception is thrown? When you try to save changes on data context ? Commented Sep 24, 2014 at 8:04
  • yes exactly when I try to save changes Commented Sep 24, 2014 at 8:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.