html.partial的一个bug?

主视图:

 @Html.Partial("SeriesChartPartial", ViewBag.deviceEveyDayActivity as List<SeriesChartVM>)

分布视图:

  
@using Magmoud.Web.ViewModels
@model List<SeriesChartVM>
@(Html.Telerik().Chart(Model).Legend(false).Name("SingleChart")
           .Series(series =>
                       {
                               if (ViewBag.IOSSelect == "true")
                               {
                                   series.Line(s => s.IOSCount).Color(UISetting.IOSCOLOR);
                               }
                               if (ViewBag.AndroidSelect == "true")
                               {
                                   series.Line(s => s.AndroidCount).Color(UISetting.ANDROIDCOLOR);
                               }
                               if (ViewBag.WindowsSelect == "true")
                               {
                                   series.Line(s => s.WindowsCount).Color(UISetting.WINDOWSCOLOR);
                               }

                       }).CategoryAxis(axis => axis
                                                           .Categories(s => s.XData)
           )
           .ValueAxis(axis => axis
                                  .Numeric()).Tooltip(true))

这样是没问题的。

但是如果改变主视图,尝试使用html.partial的第三个重载:

@Html.Partial("SeriesChartPartial", ViewBag.deviceEveyDayActivity as List<SeriesChartVM>,
    new ViewDataDictionary { 
                            { "chartType", ViewBag.deviceEveyDayActivityChartType as string }, 
                           })

VS没有报异常,但分部视图就无法渲染了。猜测是ViewBag.IOSSelect等没有数据,于是将主视图改为:

@Html.Partial("SeriesChartPartial", ViewBag.singleViewDuration as List<SeriesChartVM>,
    new ViewDataDictionary { 
                           { "iosSelect", ViewBag.iosSelect },
                           { "androidSelect", ViewBag.androidSelect },
                           { "windowsSelect", ViewBag.windowsSelect }
                           })

分部视图改为:

@using Magmoud.Web.ViewModels
@model List<SeriesChartVM>
@(Html.Telerik().Chart(Model).Legend(false).Name(ViewData["name"] as string)
           .Series(series =>
                       {
                               if (ViewData["iosSelect"] as string == "true")
                               {
                                   series.Line(s => s.IOSCount).Color(UISetting.IOSCOLOR);
                               }
                               if (ViewData["androidSelect"] as string == "true")
                               {
                                   series.Line(s => s.AndroidCount).Color(UISetting.ANDROIDCOLOR);
                               }
                               if (ViewData["windowsSelect"] as string == "true")
                               {
                                   series.Line(s => s.WindowsCount).Color(UISetting.WINDOWSCOLOR);
                                }
                       }).CategoryAxis(axis => axis
                                                           .Categories(s => s.XData)
           )
           .ValueAxis(axis => axis
                                  .Numeric()).Tooltip(true))

就运行正常了。原因不知。

posted @ 2013-02-16 20:19  瓜王  阅读(1586)  评论(0编辑  收藏  举报