转帖:Html.BeginForm
Html.BeginForm与Ajax.BeginForm都是MVC架构中的表单元素,它们从字面上可以看到区别,即Html.BeginForm是普通的表单提交,而Ajax.BeginForm是支持异步的表单提交,这对于我们开发者来说是一个福音,我们不用再自己去用JQ代码了,直接用MVC自代的Ajax.BeginForm就可以很容易的完成一个异步的表单提交动作。
Html.BeginForm的原型解释:
一、
@using (Html.BeginForm()) {} //提交到当前页面
@using (Html.BeginForm())
{
<p>Your name:@Html.TextBoxFor(x=>x.Name)</p>
<p>Your email:@Html.TextBoxFor(x => x.Email)</p>
<p>Your phone:@Html.TextBoxFor(x => x.Phone)</p>
<p>
Will you attend?
@Html.DropDownListFor(x => x.WillAttend, new[]{
new SelectListItem(){
Text="Yes.I'll be there",Value=bool.TrueString
},new SelectListItem(){
Text="No,I can't cpme",Value=bool.FalseString
}
}, "Choose an option")
</p>
<input type="submit" value="Submit RSVP"/>
}
二、
@using (Html.BeginForm(new {} )) {} //提交到当前页面,并可以传递参数
@using (Html.BeginForm(new {Name="yhf2014" }))
{
@* <p>Your name:@Html.TextBoxFor(x=>x.Name)</p>*@
<p>Your email:@Html.TextBoxFor(x => x.Email)</p>
<p>Your phone:@Html.TextBoxFor(x => x.Phone)</p>
<p>
Will you attend?
@Html.DropDownListFor(x => x.WillAttend, new[]{
new SelectListItem(){
Text="Yes.I'll be there",Value=bool.TrueString
},new SelectListItem(){
Text="No,I can't cpme",Value=bool.FalseString
}
}, "Choose an option")
</p>
<input type="submit" value="Submit RSVP"/>
}三、
@using (Html.BeginForm("action","controller")) {} //提交到指定controller下的action中
@using (Html.BeginForm("RsvpForm", "Home"))
{
<p>Your name:@Html.TextBoxFor(x=>x.Name)</p>
<p>Your email:@Html.TextBoxFor(x => x.Email)</p>
<p>Your phone:@Html.TextBoxFor(x => x.Phone)</p>
<p>
Will you attend?
@Html.DropDownListFor(x => x.WillAttend, new[]{
new SelectListItem(){
Text="Yes.I'll be there",Value=bool.TrueString
},new SelectListItem(){
Text="No,I can't cpme",Value=bool.FalseString
}
}, "Choose an option")
</p>
<input type="submit" value="Submit RSVP"/>
}
四、
@using (Html.BeginForm("action","controller",FormMethod.POST)) {} //提交到指定controller下的action中,并指定提交方式
@using (Html.BeginForm("RsvpForm", "Home", FormMethod.Post))
{
<p>Your name:@Html.TextBoxFor(x=>x.Name)</p>
<p>Your email:@Html.TextBoxFor(x => x.Email)</p>
<p>Your phone:@Html.TextBoxFor(x => x.Phone)</p>
<p>
Will you attend?
@Html.DropDownListFor(x => x.WillAttend, new[]{
new SelectListItem(){
Text="Yes.I'll be there",Value=bool.TrueString
},new SelectListItem(){
Text="No,I can't cpme",Value=bool.FalseString
}
}, "Choose an option")
</p>
<input type="submit" value="Submit RSVP"/>
}
五、
@using (Html.BeginForm("action","controller",FormMethod.POST,bject htmlAttributes)) {} //提交到指定controller下的action中,并指定提交方式,并给form一个属性。
@using (Html.BeginForm("RsvpForm", "Home", FormMethod.Post, new {name="rsvpForm1" }))
{
@* <p>Your name:@Html.TextBoxFor(x=>x.Name)</p>*@
<p>Your email:@Html.TextBoxFor(x => x.Email)</p>
<p>Your phone:@Html.TextBoxFor(x => x.Phone)</p>
<p>
Will you attend?
@Html.DropDownListFor(x => x.WillAttend, new[]{
new SelectListItem(){
Text="Yes.I'll be there",Value=bool.TrueString
},new SelectListItem(){
Text="No,I can't cpme",Value=bool.FalseString
}
}, "Choose an option")
</p>
<input type="submit" value="Submit RSVP"/>
}
转帖:Html.BeginForm的更多相关文章
- Ajax.BeginForm方法 参数
感谢博主 http://www.cnblogs.com/zzgblog/p/5454019.html toyoung 在Asp.Net的MVC中的语法,在Razor页面中使用,替代JQuery的Aja ...
- ASP.NET MVC Html.BeginForm 设置 timeout
示例代码: @using (Html.BeginForm("PublishSubmit", "Blog", FormMethod.Post, new { id ...
- MVC Html.BeginForm 与 Ajax.BeginForm 使用总结
最近采用一边工作一边学习的方式使用MVC5+EF6做一个Demo项目, 期间遇到不少问题, 一直处于研究状态, 没能来得及记录. 今天项目进度告一段落, 得以有空记录学习中遇到的一些问题. 由于MVC ...
- ASP.NET MVC 混搭 ASP.NET WebForms 所导致的 Html.ActionLink/BeginForm 问题
首先,需要了解下这篇博文:<ASP.NET WebForms MapPageRoute 路由配置> 之前,在 ASP.NET MVC 中混搭 ASP.NET WebForms,使用 Map ...
- Ajax.BeginForm VS Html.BeginForm
有的人说,AJAX一听,高大上,HTML一听,死老土,所以AJAX更好.其实这是错误的.每种方法有它不同的用途.现在做如下总结: @using (Ajax.BeginForm("Login& ...
- MVC之Ajax.BeginForm使用详解之更新列表
1.首先,请在配置文件设置如下:(该项默认都存在且为true) <add key="UnobtrusiveJavaScriptEnabled" value="tru ...
- Ajax.BeginForm参数详解
在Asp.Net的MVC中的语法,在Razor页面中使用,替代JQuery的Ajax使用,方便快捷. 使用Ajax.BeginForm方法会生成一个form表单,最后以Ajax的方式提交表单数据:需要 ...
- nginx负载均衡基于ip_hash的session粘帖
nginx负载均衡基于ip_hash的session粘帖 nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除 ...
- MVC中自带的异步((Ajax.BeginForm)无效
1.确定unobtrusive-ajax已经引用,VS2012带,2013不带 2.注意jq和unobtrusive-ajax引用顺序问题,确保jq在前 3.注意JQ和unobtrusive-ajax ...
随机推荐
- python练习之list
请用索引取出下面list的指定元素: # -*- coding: utf-8 -*- L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python' ...
- python读取word表格内容(1)
1.首页介绍下word表格内容,实例如下: 每两个表格后面是一个合并的单元格
- github--新手使用错误分析
先上去github 或者任意托管的网站.注册账号,新建仓库, 在本地运行Xcode 新建工程,新建工程的时候 勾上本地 的仓库,然后 在本地的项目根目录执行下边的命令: git remote add ...
- ASP.NET MVC 项目分离
ASP.NET MVC 项目分离 说明: ZRT.Web 是前台网站,目录[D:\ZRT.Web\] ZRT.Admin 是后台管理,目录[D:\ZRT.Web\Applications\Admin\ ...
- 类比的方法学习Performance_schema
引用自:http://www.javacoder.cn/?p=332 MySQL在5.6版本中包含了一个强大的特性——performance-schema,合理的使用这个数据库中的表,能为我们解决一些 ...
- 如何在windows的DOS窗口中正常显示中文(UTF-8字符)
打开CMD.exe命令行窗口,通过 chcp命令改变代码页 UTF-8的代码页为65001,ANSI/OEM - 简体中文 GBK为936,window default OEM - 美国为437 如果 ...
- QT 下把编辑框内的中文字符转换为 char*
第一种方法 QString str(tr("你好")); wchar_t wc[100] = {0}; pEditShortDes->text().toWCharArray( ...
- BASE64URL解析
BASE64URL是一种在BASE64的基础上编码形成新的加密方式,为了编码能在网络中安全顺畅传输,需要对BASE64进行的编码,特别是互联网中. BASE64URL编码的流程: .明文使用BASE6 ...
- 视频主观质量评价工具:MSU Perceptual Video Quality tool
MSU Perceptual Video Quality tool是莫斯科国立大学(Moscow State University)的Graphics and Media Lab制作的一款视频主观评价 ...
- java web分享ppt大纲 -- servlet容器简介
今天在公司分享了java web的ppt,把ppt大纲放在这里,希望可以帮助需要的人 servlet容器简介 定义 狭义上的,servlet容器为java Web应用提供运行时环境,负责管理servl ...