http://www.cnblogs.com/freeliver54/p/3747836.html
本文转自:http://stackoverflow.com/questions/11767911/mvc-httppost-httpget-for-action
Controller:
[HttpGet] public ActionResult MyMethod() { return MyMethodHandler(); } [HttpPost] [ActionName("MyMethod")] public ActionResult MyMethodPost() { return MyMethodHandler(); } private ActionResult MyMethodHandler() { // handle the get or post request return View("MyMethod"); }
View:
查询调用Get
<%Html.BeginForm("ActionName", "ControllerName", FormMethod.Get);%>
<% Html.Submit("BtnSearchText","btnSearch"); %>
<%Html.EndForm();%>
保存使用Post
<%Html.BeginForm("ActionName", "ControllerName", FormMethod.Post);%>
<% Html.Submit("BtnSaveText","btnSave"); %>
<%Html.EndForm();%>

本文详细介绍了ASP.NET MVC中GET与POST请求的区别及应用。通过具体的代码示例展示了如何在控制器中定义GET和POST方法来处理不同的HTTP请求,并在视图中使用HTML辅助方法实现表单提交。

424

被折叠的 条评论
为什么被折叠?



