开发者

Is it possible to have one view for two action in asp.net mvc3 razor view?

I need to add time zone in view.

dynamic viewData = new ExpandoObject();
          开发者_开发百科  viewData.TimeZones = from p in TimeZoneInfo.GetSystemTimeZones()
                                 select new SelectListItem
                                 {
                                     Text = p.DisplayName,
                                     Value = p.Id
                                 };

How can I send "viewData" to view. I have done it in different action, but cannot do this in same action.


You could use ViewBag:

public ActionResult Index()
{
    ViewBag.TimeZones = 
        from p in TimeZoneInfo.GetSystemTimeZones()
        select new SelectListItem
        {
            Text = p.DisplayName,
            Value = p.Id
        };
    return View();
}

and in the view:

@Html.DropDownList(
    "SelectedTimeZone", 
    (IEnumerable<SelectListItem>)ViewBag.TimeZones
)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜