c# - How to use EditorFor with DateTime in ASP.NET MVC5 with EF? -


i building little crud application in asp.net mvc5. instead of own model using autogenerated models of ef. table (named "tablex") accessed ef has datetime value (named "inserted").

controller:

// show edit public async task<actionresult> edit(int? id) {     tablex x = await db.tablex.findasync(id);     return view(x); }  // edit public async task<actionresult> edit([bind(include = "id,...,updated")] tablex x) {     if (modelstate.isvalid)     {         x.inserted = datetime.now;         db.entry(x).state = entitystate.modified;         await db.savechangesasync();         return redirecttoaction("index");     }     return view(x); } 

this shortened controller. can see override datetime field anyway.

view:

@model databaseef.models.tablex @using (html.beginform()) {     <div....> //more fields     <div ...>         @html.label("inserted ", ...)         <div ...>             @html.editorfor(model => model.inserted, ...)             @html.validationmessagefor(model => model.inserted, "", ...)         </div>         <input type="submit" value="save" ... />     </div> } 

with editorfor-textbox shows date "28.05.2015 17:12:17" (german format). when pressing "save" view warns field mus date. changing value e.g. "2010-10-10" works perfectly.

now found solutions annotations model "datatype(datatype.date)]". model autogenerated ef i'm looking working solution.

anybody me out there?


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -