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的更多相关文章

  1. Ajax.BeginForm方法 参数

    感谢博主 http://www.cnblogs.com/zzgblog/p/5454019.html toyoung 在Asp.Net的MVC中的语法,在Razor页面中使用,替代JQuery的Aja ...

  2. ASP.NET MVC Html.BeginForm 设置 timeout

    示例代码: @using (Html.BeginForm("PublishSubmit", "Blog", FormMethod.Post, new { id ...

  3. MVC Html.BeginForm 与 Ajax.BeginForm 使用总结

    最近采用一边工作一边学习的方式使用MVC5+EF6做一个Demo项目, 期间遇到不少问题, 一直处于研究状态, 没能来得及记录. 今天项目进度告一段落, 得以有空记录学习中遇到的一些问题. 由于MVC ...

  4. ASP.NET MVC 混搭 ASP.NET WebForms 所导致的 Html.ActionLink/BeginForm 问题

    首先,需要了解下这篇博文:<ASP.NET WebForms MapPageRoute 路由配置> 之前,在 ASP.NET MVC 中混搭 ASP.NET WebForms,使用 Map ...

  5. Ajax.BeginForm VS Html.BeginForm

    有的人说,AJAX一听,高大上,HTML一听,死老土,所以AJAX更好.其实这是错误的.每种方法有它不同的用途.现在做如下总结: @using (Ajax.BeginForm("Login& ...

  6. MVC之Ajax.BeginForm使用详解之更新列表

    1.首先,请在配置文件设置如下:(该项默认都存在且为true) <add key="UnobtrusiveJavaScriptEnabled" value="tru ...

  7. Ajax.BeginForm参数详解

    在Asp.Net的MVC中的语法,在Razor页面中使用,替代JQuery的Ajax使用,方便快捷. 使用Ajax.BeginForm方法会生成一个form表单,最后以Ajax的方式提交表单数据:需要 ...

  8. nginx负载均衡基于ip_hash的session粘帖

    nginx负载均衡基于ip_hash的session粘帖 nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除 ...

  9. MVC中自带的异步((Ajax.BeginForm)无效

    1.确定unobtrusive-ajax已经引用,VS2012带,2013不带 2.注意jq和unobtrusive-ajax引用顺序问题,确保jq在前 3.注意JQ和unobtrusive-ajax ...

随机推荐

  1. MyEclipseアンロックの手順

    ↓ ↓ ↓ ↓ ↓ ↓

  2. java使用验证码进行登录验证

    随机生成4位验证码,将生成的4位数字字母数字放入session private static void outputVerifyCode(HttpServletRequest request, Htt ...

  3. break的使用例一

    /* Name:break的使用例一 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月21日 02:28:24 Description:本程序代码无如何含 ...

  4. SQL Server 内存不足引起的并发症

    第一:cpu 1.内存不足就会有频繁的页面调入调出.这个过程是要有cpu的参与的.所以这个要影响cpu! 2.内存不足可能会引有用起执行计划被清除.当起次要执行时.这个就要重编译一次!

  5. centos 修改shm

    Linux下,Oracle 11g的自动内存管理不能指定大于这个/dev/shm的总量内存.否则就会出现如下错误 ORA-00845: MEMORY_TARGET not supported on t ...

  6. POJ1363:Rails

    Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...

  7. 使用python抓取知乎日报的API数据

    使用 urllib2 抓取数据时,最简单的方法是: import urllib2, json def getStartImage(): stream = urllib2.urlopen('http:/ ...

  8. zoj 2229 Ride to School

    所有车子到达的总时间算出来,然后从小到大排序,如果:1. 开始时间 < 0 的,不予考虑,太快的赶不上,太慢的赶上也没用.2. 开始时间 > 0 的,Charley 和最早到达的车子一起到 ...

  9. Creating a Broker (创建代理)

    1,CMD中运行 2,apollo的目录结构. bin  执行相关的脚步. etc  保存实例的配置文件 data  存储消息的文件 log 日志 tmp 临时的文件 3,Broker Configu ...

  10. java 类排序

    参考文档:Java排序: Comparator vs Comparable 入门 java类经常面临排序问题,据我所知:java提供comparable和comparator两种比较方式: 1. co ...