0

I am developing an application using MVC. I am trying to pass a value (as parameter) using Jquery function which sends the value to a controller throgh ajax. The parameter is like '01/12/2021' which is date in 'dd/mm/yyyy' format. I am using an anchor tag like:

<a href='javascript:ViewDocDetails(@item.UploadDate.ToString())'>@Html.DisplayFor(modelItem => item.UploadDate)</a>

The function is like:

function ViewDocDetails(UploadDate) {
   alert(UploadDate);
....

}

When I run the program the alert gives a value like '0.00004123371268349002'. How can I solve the problem?

Partha
  • 469
  • 2
  • 14
  • 32
  • 1
    Does this answer your question? [@Html.DisplayFor - DateFormat ("mm/dd/yyyy")](https://stackoverflow.com/questions/28114874/html-displayfor-dateformat-mm-dd-yyyy) – Abdul Ahmad Dec 01 '21 at 21:34
  • Your MVC view is using `@item` but you've not explained what that is. Your `@Html.DisplayFor()` lambda expression has a parameter `modelItem` but you use a property on `item`. You need to give a clearer example of the problem you have. Your question does not appear to involve jQuery only some JavaScript which isn't the source of the problem. – Dave Anderson Dec 01 '21 at 21:49
  • @Dave Anderson The anchor tag is inside a loop like: – Partha Dec 01 '21 at 21:56
  • So what type of object is in your collection you loop over? Is `UploadDate` a `DateTime` value and have you looked at [Standard date and time format strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings)? – Dave Anderson Dec 01 '21 at 22:08
  • @Dave-Anderson it is in string format ('dd/mm/yyyy'). Probably the '/' is giving this error. – Partha Dec 01 '21 at 23:17
  • For proper help you will need to [create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example), it is impossible to guess your problem with the code you have provided. – Dave Anderson Dec 01 '21 at 23:35

0 Answers0