zoukankan      html  css  js  c++  java
  • mvc3.0 中dropdownlist的使用

    0. 普通的下拉框
    @Html.DropDownList("type", DataHelper.GetOrderStatus(null, "--全部订单--"), new { @style = "160px" })

      1. typeof(Gender) 利用的枚举。

    @model SearchEView
    @Html.EnumDropdown(Model, m => m.Gender, null, typeof(Gender))
    

      2.ajax的dropdown请求。

    @Html.Hidden("trainId", 0)
            @Html.AjaxDropdown("ClassId", null, "AuthorClass", "GetItems", "trainId", new { }, "search")

    在搜索search中,ajax的dropdown控件名称都是以search.为前缀的,在搜索的时候用searchView 能传过去值。
    "ClassId" 是获取的值,null 是传值参数,authorclass 是control,getItems是action,trainId是搜索参数

    带三个参数的获取dropdownlist值的方法

    类 型:<br />
            @Html.EditorFor(m=>m.Setting)
            @Html.ValidationMessageFor(m=>m.Setting)

    @Html.Hidden("Refresh","") @Html.AjaxDropdown("ParentId", null, "AuthorClass", "GetItems", "Refresh", new { @class = "def" }, null, Setting => "TrainId")
     public override ActionResult GetItems(int? key, int? search,int? trainId)
             {
                 key = key ?? 0;
                 trainId = trainId ?? search;
                 if (key != 0)
                 {
                     trainId=service.GetById(key).Setting;
    
                 }
                 if (trainId == null&&key==0)
                 {
                     trainId = -1;
                 }
                 var models = service.GetAll().Where(m => m.Setting == trainId);
                 var tree = new ClassTree<IClassModel>(models);
                if (trainId.HasValue)
                {
                    tree = tree.Format(new AuthorClass { ClassName = "全部" });
                }
    
                var treeModels = tree.Select(m =>
                    new SelectListItem
                    {
                        Text = Server.HtmlEncode(m.ClassName),
                        Value = m.ClassId == 0 ? "" : m.ClassId.ToString(),
                        Selected = (m.ClassId == key)
                    }).ToList();
                 
                 return Json(models==null?null:treeModels);
             }
  • 相关阅读:
    【CSS 第五天】背景,边框
    CSS Sprite雪碧图
    【ASP】session实现购物车
    【ASP】response和sever对象实现用户登录
    【操作系统】银行家算法
    【操作系统】先来先服务
    【操作系统】多级反馈队列算法
    【页面置换算法】LRC算法和FIFS算法
    Alpha版(内部测试版)发布
    项目结束--事后诸葛亮会议总结
  • 原文地址:https://www.cnblogs.com/sunShineJing/p/2822975.html
Copyright © 2011-2022 走看看