Javascript, Razor and Escape characters. Like apostrophe

后端 未结 5 1910
不知归路
不知归路 2020-12-01 05:08

I am using Razor in my MVC3 project. And also I\'m using FullCalendar JQuery plugin. So when I\'m trying to fill the array it works good. Except one thing. If s.Name

5条回答
  •  误落风尘
    2020-12-01 05:45

    Try like this:

    $(function () {        
        $('#calendar').fullCalendar({
            header: {
                left: '',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            month: 5,
            year: 2011,
            editable: false,
            events: @Html.Raw(new JavaScriptSerializer().Serialize(ViewBag.Sessions))
        });
    });
    

    ViewBag.Sessions might require some modifications to achieve the desired result (in terms of property names), which brings me to the usual remark I make about ViewBag when I see someone using it: using ViewBag is bad practice and I would recommend you using a strongly typed view with a view model.

提交回复
热议问题