欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

一个二级联动

程序员文章站 2022-07-04 11:01:19
[HttpGet] public ActionResult JsonList() { int itemselect = ConvertHelper.SafeRequest("itemselect",0);//一级 int ProfessionID = ConvertHelper.SafeReques ......
<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;
}



 效果图如图所示;

一个二级联动