MVC Javascript Serialization Format
I am using @(new JavaScriptSerializer().Serialize(Model.DateSlotModel)))
in my view and it causing a javascript error because it produces the following when in the script block:
var initialData = [{"DateID":"1","DateValue":"4/1/2011"}]);
What do I need to do to get the output to be fo开发者_如何学编程rmated as follows?
[{"DateID":"1","DateValue":"4/1/2011"}]
Controller Code:
jobmodel.DateSlotModel = from d in eventRepository.GetEventDates(eventid)
select new ScheduleDateSlotViewModel
{
DateID = d.DateID.ToString(),
DateValue = d.DateValue.ToShortDateString()
};
Thanks
Have you tried:
var InitialData = @Html.Raw(new JavaScriptSerializer().Serialize(Model.DateSlotModel)))
精彩评论