I\'m passing this ViewModel to my View:
public class DashboardViewModel
{
public List UserTasks {get; set;}
public List
You should probably take a few steps back to understand what is going on here. A web request is really just a bunch of strings, MVC .net does some stuff to try and ease the transition from using objects to just straight string but as you can see it can't do everything. So the take-away is that you to deal with things as if they are all strings when rendered on the page.
That being said there are a number of ways to solve this problem. You can as mentioned before convert all your WorkItem objects to javascript objects and pull them out of the javascript array. Or what I personally like to do is simply have the button contain the id of the object and do an ajax call to get the most recent data from the server.
Back end:
[HttpPost]
public string GetWorkItemById(int id)
{
//get or create WorkItem here
WorkItem workItem = new WorkItem(id);
workItem.Name = "Foobar";
workItem.HoursLogged = "127001";
return Newtonsoft.Json.JsonConvert.SerializeObject(workItem);
}
Front end:
$(buttonEl).click(function () {
var id = this.value; //assuming you store the id in the button's value
$.ajax({
type: "POST",
url: "@(Url.Action("GetWorkItemById"))",
data: ({
Id:id
}),
success: success,
dataType: dataType,
success: function(result){
var name = result.Name; // Foobar
var hoursLogged = result.HoursLogged; // 127001
//populate text fields using jquery
}
})
});