转帖: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 ...
随机推荐
- Android 常用动画小结
1. 渐入动画 // Request the next activity transition (here starting a new one). startActivity(new Intent( ...
- 从零开始PHP学习 - 第三天
写这个系列文章主要是为了督促自己 每天定时 定量消化一些知识! 同时也为了让需要的人 学到点啥~! 本人技术实在不高!本文中可能会有错误!希望大家发现后能提醒一下我和大家! 偷偷说下 本教程最后的目 ...
- bzoj 3289: Mato的文件管理 莫队+线段树
题目链接 给一些询问,每个询问给出区间[L, R] , 求这段区间的逆序数. 先分块排序, 然后对于每次更改, 如果是更改L, 那么应该查询区间内比他小的数的个数, 如果更改R, 查区间内比他大的数的 ...
- (转)C++笔记:面向对象编程基础
非常棒的总结 http://blog.csdn.net/liufei_learning/article/details/21312701 面向对象编程基础 面向对象编程基于三个基本概念: 数据抽象-类 ...
- RedHat升级内核成功
升级前 uname -aLinux localhost.localdomain 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x8 ...
- android小知识之邮箱地址输入自动完成
虽然不难,但是容易忘记,做个备忘吧 package com.guet.zhuge; import android.app.Activity; import android.os.Bundle; imp ...
- Qt窗口屏幕居中显示(有专门的QDesktopWidget,先计算后显示)
窗口的屏幕居中显示问题,在各开发工具中原理相同,首先使用特定的方法得到显示屏幕的宽度和高度,再根据窗口本身的宽度和高度计算出窗口的左上角坐标位置. Qt中可以采用两种方法达到窗口的屏幕居中显示: 方法 ...
- 动画画圆的效果特效ios源码
一款不错的支持动画画圆的效果特效源码,该效果实现了动画画圆,还可以扩展成画其他平面图形功能等,大家可以下载看看吧. //定义所需要画的图形 -(void)intiUIOfView { U ...
- HDU1069:Monkey and Banana(DP+贪心)
Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T ...
- [置顶] 【cocos2d-x入门实战】微信飞机大战之四:飞机登场咯
转载请表明地址:http://blog.csdn.net/jackystudio/article/details/11757175 昨天收到了电子工业出版社寄过来的<cocos2d-x游戏开发之 ...