开发者

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)))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜