Html.BeginForm():该方法用于构建一个From表单的开始,

他的构造方法为:Html.BeginForm("ActionName","ControllerName",FormMethod.method)

1、Views代码

1 @using (Html.BeginForm("add", "book", FormMethod.Post)) { 
2     <span>name:</span>
3     @Html.TextBox("name")
4     <input type="submit" value="add" />
5 }

2、Controllers代码

1 [HttpPost]
2         public string add()
3         {
4             return "name=" + Request.Form["name"];
5         }

或者

1 [HttpPost]
2         public string add(string name)
3         {
4             return "name=" + name;
5         }

说明:

HttpPost:表示该方法只处理Http Post的请求,意思是:发送数据

HttpGet:表示该方法只处理Http Get的请求,意思是:获取数据

HttpDelete:表示该方法只处理Http Delete的请求,意思是:删除数据

HttpPut:表示该方法只处理Http Put的请求,意思是:上传数据

相关文章:

  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
猜你喜欢
  • 2021-09-21
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
相关资源
相似解决方案