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
)
精彩评论