Html.BeginForm())与Ajax.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=""
二、Ajax.BeginForm()
@using (Ajax.BeginForm("Search", new RouteValueDictionary { { "id", "" } },
new AjaxOptions { UpdateTargetId = "ListData", HttpMethod = "Get", InsertionMode = InsertionMode.Replace },
new RouteValueDictionary { { "id", "searchForm" } }))
{……}
注释:创建了一个ajax的表单,其中动作是Search,参数id是"",http请求的方法是Get,插入方式是替换(如果你做的是瀑布流,还可以用追加),这个表单本身的id是searchForm
Ajax.BeginForm异步表单原型解释
1 @using (Ajax.BeginForm( 2 new AjaxOptions 3 { 4 UpdateTargetId = "UserLogOnContainer", 5 HttpMethod = "Post", 6 OnSuccess = " ", 7 })){} //提交到当前页面,提交方式为Post,异步更新模块ID为UserLogOnContainer 8 9 @using (Ajax.BeginForm("action", "controller", null, 10 new AjaxOptions 11 { 12 UpdateTargetId = "UserLogOnContainer", 13 HttpMethod = "Post", 14 OnSuccess = " ", 15 })) 16 {} //提交到指定controller下的action,提交方式为Post,异步更新模块ID为UserLogOnContainer
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。