entity framework - Remove stubborn default value in DateTime text box in partial view - Asp.net MVC 5 -



entity framework - Remove stubborn default value in DateTime text box in partial view - Asp.net MVC 5 -

i have partial view controls in it. 1 of them textbox used come in datetime value in it. datetime textbox readonly, , type attribute text (to prevent browser date selector popup beingness shown). datetime property in model class in not nulable , unique. cannot nullable.

since textbox read only, datetime value entered using jquery datepicker timepicker addon, clicking in textbox , selecting relevant date in datepicker popup.

important: although partial view embedded in normal view, not rendered in it. partial view, form, displayed in jquery modal when user clicks action link on normal view. partial view embedded html.action method.

everything works should. problem is, however, when partial view shown in jquery modal, datetime text box shown placeholder text monday 01, january, 0001.

on other pages in application datetime controls in them, needed alter type attribute “text” , add together html placeholder @placeholder ="select date", did not work.

any assistance appreciated

edited title : changed "placeholder" "default value"

model

[index(isunique = true)] [datatype(datatype.date)] [displayformat(dataformatstring = "{0:dddd dd, mmmm, yyyy hh:mm}", applyformatineditmode = true)] [display(name = "record date")] public datetime recorddate { get; set; }

controller

//[httppost] //[validateantiforgerytoken] public actionresult createnewrecordonpopup([bind(include = "recordid,recorddate,teamperiodid,teamondutyid")] record record) { viewbag.teamondutyid = new selectlist(db.teamondutys, "teamondutyid", "name"); viewbag.teamperiodid = new selectlist(db.teamperiods, "teamperiodid", "name"); homecoming partialview("_createnewrecordonpopuppv", record); }

partial view in normal view

@html.action("createnewrecordonpopup", "records")

partial view

@html.editorfor(model => model.recorddate, new { htmlattributes = new { @class = "form-control", @readonly = "readonly", @type = "text", placeholder = "select date" } })

your datetime property non-nullable, comes default value of default(datetime), 1/1/0001 12:00:00 am. it's not placeholder. it's literally initial value because has set something.

to rid of this, create datetime nullable, i.e. datetime?. can still enforce set decorating [required] if need to. however, since it's nullable, it's default value null or empty string in input.

asp.net-mvc entity-framework

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -