【发布时间】:2017-03-10 12:22:49
【问题描述】:
我是 C#/Razor 的新手,不知道如何使用 post 方法传递表单数据。这是我尝试过的:
在 login.cshtml 中:
string username = Request.Form["username"];
string password = Request.Form["password"];
和
string username = Request.Form.Get("username");
string password = Request.Form.Get("password");
在_AppStart.cshtml中,我试过了:
AppState["username"] = HttpContext.Current.Request.Form["username"];
AppState["password"] = HttpContext.Current.Request.Form["password"];
什么都不返回。
这是 login.cshtml 中的表单元素:
<form action="index.cshtml" method="post" data-ajax="false">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button type="submit">Login</button>
</form>
【问题讨论】:
-
目前还没有 MVC 方法。我正在尝试像在具有服务器端脚本的一般网站中那样传递数据。
标签: c# asp.net forms post razor