MVC html.beginform & ajax.beginform

1、指定表单提交方式和路径等

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

他将在客户端产生一个类似<form action="/account/login" method="post"></form>标签

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=""

4、

@using (Html.BeginForm("Search", ViewContext.RouteData.GetRequiredString("Controller"), new RouteValueDictionary { { "id", "" } }, FormMethod.Get))

RouteValueDictionary:路由对象内部存放中间值使用的对象,比如Url模板的默认值,命名空间,地址栏传过来的参数等等;当然也可以用来存放任何Key-Value形式的任何值;http://www.cnblogs.com/Leo_wl/p/3380570.html

posted @ 2016-06-22 18:18  Chris_在IT道路上前行  阅读(186)  评论(0编辑  收藏  举报