<div>
<input type="text" name="username"/>
<input type="text" name="password"/>
<input type="submit" value="提交"/>
</div>
1、关键在于form中的name和参数必须一致
public ActionResult GetUserInfo(string username,string password)
{
return View();
}
2、FormCollection包含了表单的所有值,其实就是键值对,键就是表单字段中的name
public ActionResult GetUserInfo(FormCollection collection)
{
return View();
}
3、直接获取
public ActionResult GetUserInfo()
{
string username = Request["username"];string password = Request["password"];
}
4、通过建立一个对象来接受字段信息。只要对象的属性和name对应,系统便会自动赋值。
public ActionResult GetUserInfo(Users user)
{
string UserName=user.UserName;
return View();
}