初次设计MVC模式
登录页面:Login.aspx(只验证用户名、密码)
主页:Index.aspx
两个视图都在同一个文件夹下。怎么点击登录按钮能正确跳转到主页面?JS:登录跳转
            $.post(
           "@Url.Action('Loginin')",
           { UserName: $("#UserName").val(), Password: $("#Password").val() },
           function (data) {
               if (data.flag) {//如果验证成功,则跳转  
                   window.location.href = data.msg;
               }
               else {
                   alert(data.msg); //弹出失败信息  
               }
           });Controllers 下的方法:public ActionResult Loginin(string admin, string CheckCode)
        {
            return Json(new { flag = true, msg = Url.Action("Index", "adminController") }, JsonRequestBehavior.AllowGet);
        }为什么没有进我这个方法啊,求指教,应该怎么样验证登录跳转页面!!!

解决方案 »

  1.   

    传的参不匹配
     { UserName: $("#UserName").val(), Password: $("#Password").val() },string admin, string CheckCode
      
    *****************************************************************************
    签名档: http://feiyun0112.cnblogs.com/
      

  2.   

    [HttpPost]
    public ActionResult Loginin()
             {
                 string username = Request.Forms["UserName"].ToString();
                 string password = Request.Forms["Password"].ToString();
                 ...
                 return Json(new { flag = true, msg = Url.Action("Index", "adminController") }, JsonRequestBehavior.AllowGet);
             }
      

  3.   


    不是啊,方法都不进去,好像那个POST的跳转有问题?应该怎么改啊!
      

  4.   


    我的是MVC2,改成了这个方法,但是POST好像没起作用,应该怎么改呢,求版本指教!
      

  5.   

    为什么要这么写呢,直接form表单提交到action用FormCollection form接受表单信息,验证ok后然后在直接return RedirectToAction("index");就ok了。
    非要用ajax的话,估计是你接收参数变量名的问题,改成UserName和Password试试,记得必须跟前面提交的是一致的
      

  6.   

    1L  说的很清楚了呀  你那参数名不对嘛 传的参数名 要和你那个action里面的参数名相同
      

  7.   


    我现在改成
    [HttpPost]
    public ActionResult Loginin()
             {
                 string username = Request.Forms["UserName"].ToString();
                 string password = Request.Forms["Password"].ToString();
                 ...
                 return Json(new { flag = true, msg = Url.Action("Index", "adminController") }, JsonRequestBehavior.AllowGet);
             }这样后,还是不进这个方法。不然还有什么好的方法吗,求源码指教!谢谢
      

  8.   


     public ActionResult Loginin(string UserName, string Password)
    {}
    按一楼的改了,还是没有进方法。我的POST请求跳转是不是有错误?
      

  9.   

    你用调试工具  看下你的ajax请求路径 对不对
      

  10.   

    Post请求:
    http://localhost:3782/@Url.Action(%27Loginin%27)这是怎么回事?应该怎么改

      

  11.   

    Post请求:
    http://localhost:3782/@Url.Action(%27Loginin%27)这是怎么回事?应该怎么改

    看来是你请求的url错了
    要不你的url里面直接用/controller/action的方式 试试 看行不行
      

  12.   

    Post请求:
    http://localhost:3782/@Url.Action(%27Loginin%27)这是怎么回事?应该怎么改

    看来是你请求的url错了
    要不你的url里面直接用/controller/action的方式 试试 看行不行
     $.post(
               "/Controller/action/Loginin",
               { UserName: $("#UserName").val(), Password: $("#Password").val() },
               function (data) {
                   if (data.flag) {//如果验证成功,则跳转  
                       window.location.href = data.msg;
                   }
                   else {
                       alert(data.msg); //弹出失败信息  
                   }
               });写成这样?
      

  13.   

    chrome开发者工具看一下你的请求的地址是否正确,还有就是你的请求是不是正常的发送出去
      

  14.   

    Post请求:
    http://localhost:3782/@Url.Action(%27Loginin%27)这是怎么回事?应该怎么改

    看来是你请求的url错了
    要不你的url里面直接用/controller/action的方式 试试 看行不行
    额 可以了! 写死了没关系吗?
      

  15.   


    呵呵,不关路由的事,谢谢了,还是POST跳转那里有问题,我现在ajax跳转的URL那里写死了,应该没有关系吧! 非常感谢8楼!
      

  16.   

     $('#form1').form('submit', {
                                url: '<%=Url.Content("~/IT_Request.aspx/CreateITRequest") %>',
                                onSubmit: function () {
                                    return $('#form1').form('validate');
                                },
                                success: function (data) {
                                   
                                }
                            });
    Url.Content()
      

  17.   


    我现在改成
    [HttpPost]
    public ActionResult Loginin()
             {
                 string username = Request.Forms["UserName"].ToString();
                 string password = Request.Forms["Password"].ToString();
                 ...
                 return Json(new { flag = true, msg = Url.Action("Index", "adminController") }, JsonRequestBehavior.AllowGet);
             }这样后,还是不进这个方法。不然还有什么好的方法吗,求源码指教!谢谢0.0...你说的就是参数列表那个改成username和password呀。。脚指头想一下都跟方法内部那变量名没关系。。是我没说清楚把。蛋疼。