Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 formated 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

like image 563
scottrakes Avatar asked May 13 '26 21:05

scottrakes


1 Answers

Have you tried:

 var InitialData = @Html.Raw(new JavaScriptSerializer().Serialize(Model.DateSlotModel)))
like image 96
tvanfosson Avatar answered May 18 '26 09:05

tvanfosson