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 }
winform mvc,或者
1 [HttpPost] 2 public string add(string name) 3 { 4 return "name=" + name; 5 }
說明:
HttpPost:表示該方法只處理Http Post的請求,意思是:發送數據
HttpGet:表示該方法只處理Http Get的請求,意思是:獲取數據
HttpDelete:表示該方法只處理Http Delete的請求,意思是:刪除數據
HTML select,HttpPut:表示該方法只處理Http Put的請求,意思是:上傳數據