Kyle Oliver

Kyle Oliver

  • NA
  • 67
  • 29.1k

How to get a date to show in Edit View

Feb 11 2020 12:20 PM
I have created a Datepicker for my Employee Create View and it is working great.
Below is the code;
  1. <link href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/themes/cupertino/jquery-ui.css" rel="stylesheet" />  
  2. @section Scripts {  
  3.     <script src="~/Scripts/jquery-1.12.4.min.js"></script>  
  4.     <script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>  
  5.     <script>  
  6.   
  7.         $(document).ready(function () {  
  8.             $("#DOB").datepicker({  
  9.                 dateFormat: 'dd/mm/yy',  
  10.                 changeMonth: true,  
  11.                 changeYear: true,  
  12.                 selectMonths: 12,  
  13.                 yearRange: "c-70:"  
  14.                   
  15.             });  
  16.         });  
  17.     </script> 
 I have the same code for the Employee Edit View, however when I click on "Edit" the following error shows;
 
  1. Server Error in '/' Application.  
  2.   
  3. Input string was not in a correct format.   
  4. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.   
  5.   
  6. Exception Details: System.FormatException: Input string was not in a correct format.  
  7.   
  8. Source Error:   
  9.   
  10.   
  11. Line 99:             @Html.LabelFor(model => model.DOB, htmlAttributes: new { @class = "control-label col-md-2" })  
  12. Line 100:            <div class="col-md-10">  
  13. Line 101:                @Html.EditorFor(model => model.DOB, new { htmlAttributes = new { @class = "form-control" } })  
  14. Line 102:                @Html.ValidationMessageFor(model => model.DOB, "", new { @class = "text-danger" })  
  15. Line 103:            </div>  
  16.   
  17. Source File: C:\Users\kyle\source\repos\LMKSystem\Views\Employee\Edit.cshtml    Line: 101   
  18.   
  19. Stack Trace: 
 Below is the html for the DOB field in the Employee Edit view.
  1. <div class="form-group">  
  2.             @Html.LabelFor(model => model.DOB, htmlAttributes: new { @class = "control-label col-md-2" })  
  3.             <div class="col-md-10">  
  4.                 @Html.EditorFor(model => model.DOB, new { htmlAttributes = new { @class = "form-control" } })  
  5.                 @Html.ValidationMessageFor(model => model.DOB, "", new { @class = "text-danger" })  
  6.             </div>  
  7.         </div> 
I would like to know how i can click on "Edit" so that the DOB that was captured on the Employee Create View will show in the Employee Edit View?
 
I have Googled and YouTuded alot and still can't find the answer, please help?
 
Thanking you in advance.
 
Regards,
Kyle
 
 

Answers (2)