首页 新闻 赞助 找找看

MVC多选问题

0
悬赏园豆:40 [已解决问题] 解决于 2015-07-02 10:04

ajax我自己写了一个,但是页面加载的时候不加载,用的div的onload()事件,不起作用,

然后我看了

@Html.CheckBox()

这里面具体要怎么传值呢,我传了半天也不起作用

顺便贴一下ajax的方法:

页面:

  <div class="editor-label">
            角色选择
        </div>
        <div onload="CreateRole()">
            <ul id="getRole">
            </ul>
        </div>

ajax:

function CreateRole()
{
    var data = 0;
    $.ajax({
        type: 'post',
        async: false,
        data: { id: data },
        url: '/Menu/CreateRole',
        dataType: 'html',
        success: function (json, textStatus) {
            $("#getRole").append(json);
        },
        complete: function (XMLHttpRequest, textStatus) {
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.messager.alert("失败提示", textStatus);
        }
    });
}

后台代码:

public string CreateRole(int id)
        {
            List<CM_Menu> list = _menuService.GetRole();
            string html = "";
            if (list.Count > 0)
            {
                foreach (var item in list)
                {
                    html += "<li><label class=''><input type='checkBox'  name='getrole' value ='" + item.ShowName + "' />" + item.Name + "</label></li>";
                }
            }
            return html;
        }

这样写的时候,不知道为什么不加载,用的模板页,这是模板页的一个子页面

然后用

@Html.CheckBox("Role")

后台:

 public ActionResult Create()
        {
            ViewBag.UserCode = new SelectList(_userService.GetList(), "UserId", "UserName", new SelectListItem { Selected = true, Text = "选择用户", Value = "0" });
            ViewBag.Role = new (_menuService.GetRole(), "ShowName", "Name");
            return View();
        }

这样写也不行,我该怎么修改呢?

_Vegetables的主页 _Vegetables | 小虾三级 | 园豆:586
提问于:2015-07-01 17:08
< >
分享
最佳答案
0

如何传值,看函数签名哇。。对于ajax,建议直接在$(funciton(){写在这里})

收获园豆:30
幻天芒 | 高人七级 |园豆:37175 | 2015-07-01 17:30

我真心都不知道毛病在哪里,我改成$(funciton(){}),就加载出来了,郁闷呀,谢谢

_Vegetables | 园豆:586 (小虾三级) | 2015-07-02 10:04

@_Vegetables: 你可以看下你的onload事件是否真的触发了~

幻天芒 | 园豆:37175 (高人七级) | 2015-07-02 10:06
其他回答(2)
0

checkbox 传值就是有选中的同名checkbox的值会拼在一起(中间用分号隔开)传给后台。

收获园豆:10
爱编程的大叔 | 园豆:30839 (高人七级) | 2015-07-01 17:34
0

ajax是Jqury库,你不写在Jqury里是不执行的!

浮云1 | 园豆:2 (初学一级) | 2015-07-03 09:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册