一个二级联动

Posted lidoudou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个二级联动相关的知识,希望对你有一定的参考价值。

<div class="layui-form-item">
        <label class="layui-form-label">所属级别:</label>
        <div class="layui-input-inline">
            <input type="hidden" id="nItemType" name="nItemType" value="" />
            @*@html.DropDownListFor(m => m.MeID, MenuHelper.GetMe(), new { @jqverify = "required", @jqerror = "请选择级别" })**@
            <select name="itemselect" id="itemselect" lay-filter="itemselect" @(Type != 0 ? "disabled" : "")>
                <option value="0">选择级别</option>

                @{

                    //foreach (DoingStudy.Entity.News_Menu iModel in new DoingStudy.Repository.News_Menu().IQueryable("MenuID", 0))
                    foreach (DoingStudy.Entity.News_Menu iModel in new DoingStudy.Repository.News_Menu().IQueryable("PID", 0))
                    {
                        string sKey = string.Empty;
                        if (nMenuID == iModel.MenuID)
                        {
                            sKey = " selected="selected" ";
                        }
                        <option @sKey value="@iModel.MenuID">@iModel.MenuName</option>
                    }
                }
            </select>
        </div>
        <div class="layui-input-inline">
            <select name="ProfessionID" id="ProfessionID">
                @{
                    <option value="0">全部 </option>
                    if (nMenuID != 0)
                    {
                        List<DoingStudy.Entity.News_Menu> NModel = new DoingStudy.Repository.News_Menu().FindList("PID", nMenuID);
                        for (var i = 0; i < NModel.Count; i++)
                        {
                            string sKey2 = string.Empty;
                            if (ExistID == NModel[i].MenuID)
                            {
                                sKey2 = " selected="selected" ";
                            }
                            <option @sKey2 value="@NModel[i].MenuID">@NModel[i].MenuName</option>
                        }
                    }

                }
            </select>
        </div>
<script>  
    layui.use(myform);   
    layui.use("form", function () {
        var form = layui.form();
        form.on(select(itemselect), function (data) {
            FillCity(data.value);
          
            document.getElementById(nItemType).value = $("#itemselect").val();
        });

        //资讯类型
        form.on(radio(NewsType), function (data) {
          
            if (data.value == 3) {
                $("#divvideo").show();
            } else {
                if (data.value == 0) {
                    $("#divphoto").hide();
                }
                else {
                    $("#divphoto").show();
                }
                $("#divvideo").hide();
            }
        });
    });
    function FillCity(provinceId) {
        $.ajax({
            url: "/NewsManage/News/GetModuleChildList?pId=" + provinceId,
            type: "GET",
            dataType: "JSON",

            success: function (cities) {
                $("#ProfessionID").html("");
               
                $.each(cities, function (i, city) {
                    $("#ProfessionID").append(("<option value=‘" + city.Value + "‘>" + city.Text + "</option>"));
                });
                layui.use("form", function () {
                    var form = layui.form();
                    form.render();
                });
            }
        });
    }
   

</script>
[HttpGet]
        public string GetModuleChildList(int pId)
        {
            return System.Web.Mvc.MenuHelper.GetModule(pId).ToJson();
        }//get请求

[HttpGet]
public ActionResult JsonList()
{
int itemselect = ConvertHelper.SafeRequest("itemselect",0);//一级
int ProfessionID = ConvertHelper.SafeRequest("ProfessionID", 0);//二级
int sMenuID = 0;
if (ProfessionID != 0)
{
sMenuID = ProfessionID;
}
else {
sMenuID = itemselect;
}
string sTitle = ConvertHelper.SafeString(Request["txtTitle"], "");
PageModel page = PageModelInstance.GetInstance();
page.PageSize = pageSize;
page.PageIndex = nowPage;
DataTable dtList = new DoingStudy.Repository.News_News().GetList(sTitle, sNewsType, sMenuID, 0, IsAudit, IsHead, pageSize, nowPage, out RowsCount);
[HttpPost]
public ActionResult Edit(DoingStudy.Entity.News_News model)
{
DoingStudy.Repository.News_News adminRep = new DoingStudy.Repository.News_News();
int itemselect = ConvertHelper.SafeRequest("itemselect", 0);//一级
int ProfessionID = ConvertHelper.SafeRequest("ProfessionID", 0);//二级
if (ProfessionID != 0)
{
model.MenuID = ProfessionID;
}

技术分享图片

 

 

 

  





























以上是关于一个二级联动的主要内容,如果未能解决你的问题,请参考以下文章

三级联动怎么回显 javaweb

JavaScript二级联动

asp二级联动下拉菜

phpcms联动菜单有啥用

省市二级联动

PHP+ajax实现二级联动菜单功能