.net - Textboxfor mvc3 date formatting and date validation -


i've decided started mvc 3 , ran issue while trying redo 1 of web apps mvc3.

i've got projects setup way:

public class project {     public int      projectid       { get; set; }      [required(errormessage="a name required")]     public string   name            { get; set; }      [displayname("team")]     [required(errormessage="a team required")]     public int      teamid          { get; set; }      [displayname("start date")]     [required(errormessage="a start date required")]     [displayformat(applyformatineditmode=true, dataformatstring="{0:d}")]     public datetime startdate       { get; set; }      [displayname("end date")]     [required(errormessage="an end date required")]     [displayformat(applyformatineditmode = true, dataformatstring = "{0:d}")]     public datetime enddate         { get; set; } } 

and entry form written way dates:

<table>     <tr>         <td>             <div class="editor-label">                 @html.labelfor(model => model.startdate)             </div>         </td>         <td>             <div class="editor-label">                 @html.labelfor(model => model.enddate)             </div>         </td>     </tr>     <tr>         <td>             <div class="editor-field">                 @html.textboxfor(model => model.startdate, new { @class = "datepicker", id="txtstartdate" })                 @html.validationmessagefor(model => model.startdate)             </div>         </td>         <td>             <div class="editor-field">                 @html.textboxfor(model => model.enddate, new { @class = "datepicker", id = "txtenddate" })                 @html.validationmessagefor(model => model.enddate)             </div>         </td>     </tr> </table> 

my problem textbox displaying 01/jan/0001 00:00:00. first: how can date formated shortdatestring? i've found mvc2 solution advised create editortemplates folder in sharedfolder , use editorfor instead did not seem working mvc3 . seemed prevent adding classes textboxfor

and secondly once fixed i've got special validation system need put in place. need have end date after start date. i'm thinking of doing check javascript found http://www.datejs.com there way validation directly on class?

for edit template try this

@model datetime? @html.textbox("", (model.hasvalue ? model.value.toshortdatestring() : string.empty), new { @class = "datepicker" }) 

source: mvc 3 editor template datetime

jquery datetime comparisons

$('#txtbox').change(function() {             var date = $(this).val();             var arrdate = date.split("/");             var today = new date();             usedate = new date(arrdate[2], arrdate[1] -1, arrdate[0]);              if (usedate > today) {                 alert('please enter correctdate');                 $(this).val('');             }         }); 

source: jquery date comparison


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -