.net mvc 一个Action的 HttpGet 和 HttpPost

时间:2023-03-08 17:51:37
.net mvc 一个Action的 HttpGet 和 HttpPost

http://www.cnblogs.com/freeliver54/p/3747836.html

本文转自:http://*.com/questions/11767911/mvc-httppost-httpget-for-action

Controller:

.net mvc 一个Action的 HttpGet 和 HttpPost
[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");
}
.net mvc 一个Action的 HttpGet 和 HttpPost

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();%>