youyouzkn
V2EX  ›  问与答

关于asp.net MVC form提交问题

  •  
  •   youyouzkn · Dec 3, 2013 · 2890 views
    This topic created in 4592 days ago, the information mentioned may be changed or developed.
    ////Login.cshtml
    <form [email protected]("~/account/login") method="post">
    <input id="inputName" type="text" />
    <input id="inputPassword" type="password" />
    <input id="submit" type="submit" value="Login" />
    </form>

    ////AccountController.cs
    public ActionResult Login(string inputName,string inputPassword)
    {
    string is_error = null;
    if (inputName=="yoyo"&&inputPassword=="123456")
    {
    RedirectToAction("~/home/index");
    }
    is_error = "用户名或者密码错误!请再试一次。";
    ViewBag.isError = is_error;
    return View();
    }

    提交后页面能跳转,但是参数传值失败,inputName和inputPassword为null 难道一定要用BeginForm的方式创建form或者只能用ajax提交么。。。求大神们解答,万分感谢。
    Supplement 1  ·  Dec 3, 2013
    已经解决!感谢万能的V2EXer
    3 replies    1970-01-01 08:00:00 +08:00
    cxe2v
        1
    cxe2v  
       Dec 3, 2013   ❤️ 1
    很久没接触过ASP.NET MVC了,但是凭直觉是你的HTML那里出问题了
    justfly
        2
    justfly  
       Dec 3, 2013   ❤️ 1
    id="inputName" 后面加上 name="inputName"
    youyouzkn
        3
    youyouzkn  
    OP
       Dec 3, 2013
    另:RedirectToAction("~/home/index") 应该改成 return RedirectToAction("index","home")
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5466 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 07:59 · PVG 15:59 · LAX 00:59 · JFK 03:59
    ♥ Do have faith in what you're doing.