V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
youyouzkn
V2EX  ›  问与答

关于asp.net MVC form提交问题

  •  
  •   youyouzkn · 2013-12-03 18:48:35 +08:00 · 2375 次点击
    这是一个创建于 3817 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ////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提交么。。。求大神们解答,万分感谢。
    第 1 条附言  ·  2013-12-03 21:59:31 +08:00
    已经解决!感谢万能的V2EXer
    3 条回复    1970-01-01 08:00:00 +08:00
    cxe2v
        1
    cxe2v  
       2013-12-03 19:57:07 +08:00   ❤️ 1
    很久没接触过ASP.NET MVC了,但是凭直觉是你的HTML那里出问题了
    justfly
        2
    justfly  
       2013-12-03 20:25:49 +08:00   ❤️ 1
    id="inputName" 后面加上 name="inputName"
    youyouzkn
        3
    youyouzkn  
    OP
       2013-12-03 22:01:43 +08:00
    另:RedirectToAction("~/home/index") 应该改成 return RedirectToAction("index","home")
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5654 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:03 · PVG 15:03 · LAX 00:03 · JFK 03:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.