1.@using(Html.BeginForm()){}                                                      //提交到当前页面

2.@using(Html.BeginForm( new {} )){}                                         //提交到当前页面,new中可以带参数

3.@using(Html.BeginForm("action","controller")){}                          //提交到指定controller下

4.@using(Html.BeginForm("action","controller",FormMethod.Post))    //指定提交方式

注:所有要提交的内容包括按钮都必须在{ }内

example:

1.指定表单提交路径和方式:

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

html格式:

<form name="nbForm" id="idForm" action="/Home/Index" method="get">  </form>

2.指定表单提交方式为文件方式:

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

html格式:略

注意, 有时候要加{id=1}不然在点击超过第一页的索引时form后面会自动加上当前页的索引,如果此时再搜索则可能会出来“超出索引值”的错误提示
@using (Html.BeginForm("Index", null, new { id = 1 }, FormMethod.Get))

3.添加new { area = string.Empty }是为了防止提交链接后面自带参数,方式自定,如可写成 new { id = ""}

@using (Html.BeginForm("Shipping", "Order", new { area = string.Empty }, FormMethod.Post, new { id = "ShippingForm" }))

4.@using(Html.BeginForm("Index","Home",FormMehod.method)){}也可以写作

<% using(Html.BeginForm("Index","Home",FormMethod.method)){%>

<%}%>

FormMethod为枚举方式

public enum FormMethod

{

Get=0,

Post=1,

}

5.控制器接受参数的方式

ex:在aspx中

@using(Html.BeginForm("Index","Home",FormMehod.Post))

{

@Html.TextBox("username")

@Html.TextBox("password")

<input type="submit" value="登陆"/>

}

控制器中

public ActionResult Index()

{

string struser=Request.Form["username"];

string strpass=Request.From["password"];

ViewData["v"]="你的账号是"+struser+"密码是"+strpass;

return View();

}

在Index.aspx中接受传值

<%=ViewData["v"]%>

ex:在MVC中

@using (Html.BeginForm("Shipping", "Order", new { area = string.Empty }, FormMethod.Post, new { id = "ShippingForm" }))

{

@Html.ValidationMessage("ShipInfo.DeliverType")
@Html.HiddenFor(m => m.ShipInfo.DeliverCountry)
@Html.HiddenFor(m => m.ShipInfo.DeliverProvince)
@Html.HiddenFor(m => m.ShipInfo.DeliverCity)
@Html.HiddenFor(m => m.ShipInfo.DeliverCityArea)

}

1. HTML标签name 和参数名一样

public ActionResult Shipping(string ShipInfo.DeliverType,string ShipInfo.DeliverCountry,string ShipInfo.DeliverProvince,string ShipInfo.DeliverCity,string ShipInfo.DeliverCityArea){}

2.HTML标签name 属性和Model属性保持一致

public ActionResult Shipping(Models.ViewModels.Order.OrderViewModel model){}

3.表单集合传参

public ActionResult Shipping( FormCollection fc)

{

string strResult=fc["selectOption"];   //集合传参要以 键值对的方式 获得数据

}

MVC HtmlHelper用法(一)@Html.BeginForm的使用总结的更多相关文章

  1. ASP.NET MVC HtmlHelper用法集锦

    ASP.NET MVC HtmlHelper用法集锦 在写一个编辑数据的页面时,我们通常会写如下代码 1:<inputtype="text"value='<%=View ...

  2. MVC HtmlHelper用法大全

    MVC HtmlHelper用法大全HtmlHelper用来在视图中呈现 HTML 控件.以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ·Actio ...

  3. C# ASP.NET MVC HtmlHelper用法大全

    UrlHrlper 下面的两个地址一样的功能 下边这个防止路由规则改变 比如UserInfo/Index改为UserInfo-Index,使用下面的不受影响 另一种形式的超链接: <%: Htm ...

  4. ASP.NET MVC HtmlHelper用法大全

    HTML扩展类的所有方法都有2个参数: 以textbox为例子public static string TextBox( this HtmlHelper htmlHelper, string name ...

  5. 【转】MVC HtmlHelper用法大全

    HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ActionLink - 链接到操作方法. B ...

  6. MVC HtmlHelper用法

    HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ActionLink - Links to a ...

  7. [转]MVC HtmlHelper用法大全

    原文链接:http://www.cnblogs.com/jyan/archive/2012/07/23/2604474.html HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了 ...

  8. 【MVC】ASP.NET MVC HtmlHelper用法大全

    1.ActionLink <%=Html.ActionLink("这是一个连接", "Index", "Home")%>   带 ...

  9. MVC中HtmlHelper用法大全参考

    MVC中HtmlHelper用法大全参考 解析MVC中HtmlHelper控件7个大类中各个控件的主要使用方法(1) 2012-02-27 16:25 HtmlHelper类在命令System.Web ...

随机推荐

  1. JS性能优化笔记搜索整理

    通过网上查找资料了解关于性能优化方面的内容,现简单整理,仅供大家在优化的过程中参考使用,如有什么问题请及时提出,再做出相应的补充修改. 一. 让代码简洁:一些简略的表达方式也会产生很好的优化 eg:x ...

  2. ffmpeg常用命令

    windows http://www.cnblogs.com/wainiwann/p/4128154.html ubuntu http://blog.csdn.net/hellowxwworld/ar ...

  3. 原生js获取Html元素的实际宽度高度

    第一种情况就是宽高都写在样式表里,就比如#div1{width:120px;}.这中情况通过#div1.style.width拿不到宽度,而通过#div1.offsetWidth才可以获取到宽度. 第 ...

  4. return和finally的执行顺序

    创建一个类,新建一个方法: public class Demo { public int get() { int x=1; try { x++; return x; }finally{ ++x; } ...

  5. ListView的HeaderView和Footer

    HeaderView介绍 HeaderView用法 属性中添加 ListView中属性listHeader和overScrollHeader区别: android:overScrollHeader=& ...

  6. mysql体系结构

    mysql逻辑架构: 第一层,即最上一层,所包含的服务并不是MySQL所独有的技术.它们都是服务于C/S程序或者是这些程序所需要的:连接处理,身份验证,安全性等等. 第二层值得关注.这是MySQL的核 ...

  7. Runtime Error---Description: An application error occurred on the server....

    [原]Runtime Error---Description: An application error occurred on the server.... 2010-1-7阅读2010 评论3 D ...

  8. javascript平时小例子③(setInterval使用1)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  9. Jquery中animate可以操作css样式属性总结

    可以用 animate() 方法来操作所有 CSS 属性吗? 是的,几乎可以!不过,需要记住一件重要的事情:当使用 animate()时, 必须使用 Camel 标记法书写所有的属性名,比如,必须使用 ...

  10. 讨论一下hibernate如何动态注册一个动态生成的实体类

    如何动态生成实体类请参考这篇博文:http://www.cnblogs.com/anai/p/4269858.html 下面说说得到实体类后,如何能使用hibernate的接口来进行数据访问. 我们都 ...