MVC3前台链接传两个参数,如果这么写<a href="/group/all_user?id=1&name=你好/">
点击链接跳转到一下页的后台group控制器all_user方法中,此方法中需要取这个id的值。下面是方法,但是怎么取这个id不会写(请教各位)
 public ActionResult all_user(int? pageIndex, int id)
        {
            pageIndex = pageIndex ?? 1; //分组页码,默认为1
            var list = gm.GetGroupMember(pageIndex.Value, pageSize);
            ViewBag.list = list;
            return View("all_user");
        }
跳转后的下一页,如果前台也需要取链接上的参数name,在前台后该怎么写(请教各位)

解决方案 »

  1.   

    a href="/group/all_user?id=1&name=你好/"  你这个方面传了二个参数 id name 
    而你public ActionResult all_user(int? pageIndex, int id)的二个参数与上面的二个参数不同,
    你将改写public ActionResult all_user(int? pageIndex, int id,string name)
    a href="/group/all_user?id=1&name=你好&pageIndex=1" 
      

  2.   

    还是用viewbag, 在view里面之间引用就行 @ViewBag.idpublic ActionResult all_user(int? pageIndex, int id)
            {
                pageIndex = pageIndex ?? 1; //分组页码,默认为1
                var list = gm.GetGroupMember(pageIndex.Value, pageSize);
                ViewBag.list = list;
                ViewBag.id= 1;
                ViewBag.Name= "你好";
                return View("all_user");
            }
      

  3.   

    参数名为id,可不写
    <a href="/group/all_user?id=1&name=你好/">
    =>
    <a href="/group/all_user/1&name=你好/">
    Action中all_user(int? pageIndex, int id),id直接拿来用就是了;若写成<a href="/group/all_user?id=1&name=你好/">
    action中用Request["id"]即可获取!
      

  4.   

    你的all_user方法那两个参数应该和你url里的参数名称保持一致:
    public ActionResult all_user(int id, name)
      

  5.   

    汗,少写了个类型:
    public ActionResult all_user(int id, string name)
      

  6.   

       public ActionResult all_user(int? pageIndex, int id,string strName)
            {
               
                pageIndex = pageIndex ?? 1; 
                var list = gs.GetGroupMember(pageIndex.Value, pageSize, id);
                ViewBag.list = list;
                ViewBag.Name = strName;
                ViewBag.id = id;
                return View("all_user");
            }<a href="/Group/[email protected]&[email protected]">