1. 程式人生 > >@using (Html.BeginForm())參數示例

@using (Html.BeginForm())參數示例

add pre blog first ear 註意 www spa 錯誤

@using (Html.BeginForm())參數示例

1、指定表單提交方式和路徑等

 @using (Html.BeginForm("Index", "Home", FormMethod.Get, new { name = "nbform", id = "nbform" }))

2、指定表單提交為數據方式(無刷新提交時前面兩個參數不要寫)

 @using (Html.BeginForm("ImportExcel", "Stock", FormMethod.Post, new { enctype = "multipart/form-data" }))

註意, 有時候要加{id=1}不然在點擊超過第一頁的索引時form後面會自動加上當前頁的索引,如果此時再搜索則可能會出來“超出索引值”的錯誤提示 @using (Html.BeginForm("Index", null, new { id = 1 }, FormMethod.Get))

3、下面的操作可以防止提交鏈接後面自帶參數

@using (Html.BeginForm("AddDIYBillOfLading", "BillOfLading", new { id ="" }, FormMethod.Post, new { name = "myform", id = "myform" }))

即,RouteValues的id=""

@using (Html.BeginForm())參數示例