0

I am working on MVC. I have scenario, where I am calling the action method from JQuery get method. My action method is returning object in JSON format. Below are my class properties,

Public Class Employee
    Public Property ID As Integer
    Public Property Name As String
    Public Property PhoneNumber As Integer
    Public Property FromDate As Date
    Public Property ThruDate As Date?   'Nullable
    Public Property Active As Boolean
    Public Property Qty As Double?      'Nullable
End Class

What is best way to send object of Employee class to jquery.

  • Should I create viewmodel with all the properties as string. convert employee entity into viewmodel and send that viewmodel object. But want to avoid this as every time I send data from client to server or vice-versa, I have to convert it to and from Employee object.
  • Send the employee object directly with the properties as it is? If yes then again on client side, I have to convert the FromDate,ThruDate properties to Date object as their format changes to string.
  • Any better approach then above?
Parag Patil
  • 93
  • 2
  • 15
  • 1
    You have not explained what the problem is or the code you use, but I suspect its as per [this question/answer](http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format). –  Feb 08 '17 at 02:39
  • 1
    And since your method appears be be using `return Json(...)`, then you can simply create an anonymous object where the `DateTime` properties are formatted as you want –  Feb 08 '17 at 02:41
  • for this you just need to have a controller action and the return type would be `JsonResult` instead of `View` – mylee Feb 08 '17 at 07:03

0 Answers0