zoukankan      html  css  js  c++  java
  • @Html.DropDownList 是如何绑定ViewData、ViewBag数据的?

    The DropDownList helper used to create an HTML select list requires a IEnumerable , either explicitly or implicitly. That is, you can pass the IEnumerable explicitly to the DropDownList helper or you can add the IEnumerable to the ViewBag using the same name for the SelectListItem as the model property

    可以传入明确的IEnumerable<SelectListItem>,也可以通过ViewBag或者ViewData隐式地传入,前提是需要相同的名称,比如:

    ViewBag.GenreId或者ViewData["GenreId"]。官方示例:

    public ActionResult SelectCategory() {
    
         List<SelectListItem> items = new List<SelectListItem>();
    
         items.Add(new SelectListItem { Text = "Action", Value = "0"});
    
         items.Add(new SelectListItem { Text = "Drama", Value = "1" });
    
         items.Add(new SelectListItem { Text = "Comedy", Value = "2", Selected = true });
    
         items.Add(new SelectListItem { Text = "Science Fiction", Value = "3" });
    
         ViewBag.MovieType = items;
        ViewData["HourList"] =items ;
    return View(); }

      视图:

    @Html.DropDownList("MovieType")

    以上来自:https://q.cnblogs.com/q/78044/

    不相同名称的处理:

    @Html.Kendo().DropDownListFor(l => l.lb).OptionLabel("Select...").DataTextField("Text").DataValueField("Value").BindTo(ViewData["HourList"] as List<SelectListItem>))
  • 相关阅读:
    ecstore中kvstore之mongodb
    ecstore中kvstore之memcached
    ecostore搜索注意事项
    ecos的dbschema
    ecos的model
    ecos的mvcl
    ecos的app处理类
    ecos的app生命周期
    Linux系统的时间设置
    数的机器码表示——彻底弄清什么是原码、反码、补码、移码
  • 原文地址:https://www.cnblogs.com/djd66/p/15166450.html
Copyright © 2011-2022 走看看