zoukankan      html  css  js  c++  java
  • 2级分类选择

     页面JS代码

    <script type="text/javascript"> function GetTypeByParentID(id) { $("#ChildType").empty(); $("#ChildType").children().remove(); $.ajax({ url: '/Entry/GetSecondType/' + $(id).val(), type: "get", datatype: "json", success: function (data) { $.each(data, function (i, item) { $("<input id="TypeId" type="radio"name="TypeId">" + item["Name"] + "</input>") .val(item["Id"]) .appendTo($("#ChildType")); }); } }); } </script>
      Controller里的代码   

    [HttpGet] public ActionResult Form(int? id) { QueryType(); EntryModel model = new EntryModel(); if (id != null) { model = business.Get(id.Value); } return View(model); } private void QueryType() { EntryTypeRepository rep = new EntryTypeRepository(); var list = rep.QueryByParentId(0); var select = new List<SelectListItem>(); foreach (var item in list) { select.Add(new SelectListItem() { Text=item.Name,Value = item.Id.ToString()}); } ViewBag.TypeList = select; } public ActionResult GetSecondType(int id = 0) { var list = new List<EntryTypeModel>(); if (id != 0) { EntryTypeRepository rep = new EntryTypeRepository(); list = rep.QueryByParentId(id); } else{ list = new List<EntryTypeModel>(); } return Json(list, JsonRequestBehavior.AllowGet); } [HttpPost] [ValidateInput(false)] public ActionResult Form(EntryModel model) { if (ModelState.IsValid) { if (model.Id == 0) { business.Add(model); } else { business.Update(model.Id,model); } ViewBag.Msg = "添加成功!"; ViewBag.ReturnUrl = "/Entry/List"; QueryType(); } return View(); }
  • 相关阅读:
    zoj 3792 Romantic Value
    uva 563
    uva 10779 Collectors Problem 网络流
    什么是撞库,如何预防撞库攻击?
    linux install redis-cli
    python远程调试及celery调试
    python HttpServer共享文件
    python引用,浅复制,深复制
    redis 查询key数量
    ubuntu查询可用安装包
  • 原文地址:https://www.cnblogs.com/isylar/p/3277514.html
Copyright © 2011-2022 走看看