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. C#中常用的与编码有关的代码

    如何将字符串转化为字符数组? char[] chars=str.ToArray(); 如何将字符串转化为字节数组? Encoding.ASCII.GetBytes(str); Encoding.Uni ...

  2. js之获取窗口大小和位置信息

    除IE外的浏览器查看窗口大小和位置信息: //The overall size of the browser window on the desktop var windowWidth = windo ...

  3. Window对象简介

    Window对象是JavaScript层级中的顶层对象. Window对象表示一个浏览器窗口或一个框架,它在<body>或<frameset>出现时被自动创建. Window对 ...

  4. DataTables.js插入数据的两种方式

    一:采用数组的方式插入值 var tableData = []; ; ; $.each(data, function (i, d) { tableData.push([idxTable, d.stcd ...

  5. 20145330第六周《Java学习笔记》

    20145330第六周<Java学习笔记> . 这周算是很忙碌的一周.因为第六周陆续很多实验都开始进行,开始要准备和预习的科目日渐增多,对Java分配的时间不知不觉就减少了,然而第十和十一 ...

  6. java web用于保持状态的4种方法

    方法一:网址重写 通过在url地址后面添加若干的token作为查询字符串来实现.token的值一般为 键=值 url?key1=value1&key2=value2&...&k ...

  7. 20145334赵文豪 《Java程序设计》第1周学习总结

    20145334赵文豪 <Java程序设计>第1周学习总结 教材学习内容总结 第一周的学习在紧张中结束了,我们这周了解了各门课的基本内容与授课形式,在第一周java课程的的学习中我们学习了 ...

  8. Kinect 图像帧的格式

    一.ColorImageFormat:彩色图像帧的格式 RawYuvResolution640x480Fps15 原始YUV格式,分辨率是640x480,每秒15帧: RgbResolution128 ...

  9. 【iCore3 双核心板_ uC/OS-III】例程二:任务的建立与删除

    实验指导书及代码包下载: http://pan.baidu.com/s/1bD7ulK iCore3 购买链接: https://item.taobao.com/item.htm?id=5242294 ...

  10. P4实验问题 解决python模块导入

    参考:Python导入自定义包或模块 在执行./run_demo.sh的过程中,遇到了python的模块问题: root@ubuntu:/home/wasdns/tutorials/SIGCOMM_2 ...