ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 66.3k

How to get value of Last working date if is display as part of div ?

Jan 22 2024 8:08 PM

I work on asp.net mvc . i face issue i can't get value of @Model.lastworkingdate.tostring("dd/MM/yyyy") on submit function java script i don't know how to get it value I can get value of lastworkingdate when it display as EditorFor but if it display as property model @Model.lastworkingdate i can't get value on submit function java script so how to get it value on submit function java script when Editor For element not exist

so my logic will be submit function of last working date

if(element editor for exist )

{

ResignationRequester.LastWorkingDate=get value of edit for last working date

}

else

{

ResignationRequester.LastWorkingDate=get value of @Model.lastworkingdate.tostring("dd/MM/yyyy")

}

what i try as below

<table style="border: 1px solid black;width:100%;">
<tr>
<td style="width: 50%; font-weight: bold; padding-top: 10px;">
   
    @Html.LabelFor(model => model.LastWorkingDate, htmlAttributes: new { @class = "control-label col-md-5" })
    <div class="col-md-7">
        @if (Session[BLL.Common.SessionKeys.RoleCode].ToString() == "REQ")
        {
            if (Model.DirectManagerStatus == "Approve" || Model.DirectManagerStatus == "Rejected by Head Department")
            {
                @Model.LastWorkingDate.ToString("dd/MM/yyyy")
                

            }
      else
       {
 @Html.EditorFor(model => model.LastWorkingDate, new { htmlAttributes = new { @class = "form-control", @id = "LastWorkingDate" } })    
        }
         }
</di>
</td>
</tr>
</table>

  function submit() {
      console.log("check submit");
          var ResignationRequester = new Object();
          
         
      var LastWorkingDateElement = document.getElementById("LastWorkingDate");
      if (LastWorkingDateElement) {
          ResignationRequester.LastWorkingDate = LastWorkingDateElement.value;
      } else {
          ResignationRequester.LastWorkingDate = "";
          console.log("empty")

      }
}

 


Answers (2)