您的位置:首页 > 理论基础 > 计算机网络

.net mvc 一个Action的 HttpGet 和 HttpPost

2015-09-28 11:56 615 查看
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();%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: