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的使用总结的更多相关文章
-
ASP.NET MVC HtmlHelper用法集锦
ASP.NET MVC HtmlHelper用法集锦 在写一个编辑数据的页面时,我们通常会写如下代码 1:<inputtype="text"value='<%=View ...
-
MVC HtmlHelper用法大全
MVC HtmlHelper用法大全HtmlHelper用来在视图中呈现 HTML 控件.以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ·Actio ...
-
C# ASP.NET MVC HtmlHelper用法大全
UrlHrlper 下面的两个地址一样的功能 下边这个防止路由规则改变 比如UserInfo/Index改为UserInfo-Index,使用下面的不受影响 另一种形式的超链接: <%: Htm ...
-
ASP.NET MVC HtmlHelper用法大全
HTML扩展类的所有方法都有2个参数: 以textbox为例子public static string TextBox( this HtmlHelper htmlHelper, string name ...
-
【转】MVC HtmlHelper用法大全
HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ActionLink - 链接到操作方法. B ...
-
MVC HtmlHelper用法
HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ActionLink - Links to a ...
-
[转]MVC HtmlHelper用法大全
原文链接:http://www.cnblogs.com/jyan/archive/2012/07/23/2604474.html HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了 ...
-
【MVC】ASP.NET MVC HtmlHelper用法大全
1.ActionLink <%=Html.ActionLink("这是一个连接", "Index", "Home")%> 带 ...
-
MVC中HtmlHelper用法大全参考
MVC中HtmlHelper用法大全参考 解析MVC中HtmlHelper控件7个大类中各个控件的主要使用方法(1) 2012-02-27 16:25 HtmlHelper类在命令System.Web ...
随机推荐
-
Android模拟器部署历程
由于想玩一款手机的游戏,本人手机Android系统版本太低,不能安装.所以就想在WindowS上安装一个模拟器,然后安装游戏.想法挺好.实现起来确实经历了一个坎坷的过程.为了让其他人少走弯路,本人把此 ...
-
Excel 代码
package com.chinabase.common.util; import java.io.FileInputStream; import java.io.FileOutputStream; ...
-
突破路由mac地址过滤思路
一.获取合法的mac地址 在拿到无线网络的密码时,主要思路就是,用类似airodump-ng这类监听软件(WildPackets OmniPeek,Kismet),获得合法客户端的mac地址,然后再更 ...
-
YUI的类型判断函数
1.首先定义一个关于类型的对象,及相关变量 类型判断对象 ar L = Y.Lang || (Y.Lang = {}), STRING_PROTO = String.prototype, TOSTRI ...
-
Linux软件间的依赖关系(转)
Linux中的软件大部分是零碎的,其粒度比windows的小很多,软件之间的依赖关系很强烈,下面是自己的一些理解: 一.Linux中的软件依赖Linux中的软件依赖关系成一颗拓扑树结构,比如A直接或间 ...
-
多校 Robot Motion
题目链接:http://acm.hust.edu.cn/vjudge/contest/124435#problem/J 密码:acm Sample Input NEESWE WWWESS SNWWWW ...
-
springmvc配置详解 教程
https://www.cnblogs.com/sunniest/p/4555801.html
-
神经网络——反向传播BP算法公式推导
在神经网络中,当我们的网络层数越来越多时,网络的参数也越来越多,如何对网络进行训练呢?我们需要一种强大的算法,无论网络多复杂,都能够有效的进行训练.在众多的训练算法中,其中最杰出的代表就是BP算法,它 ...
-
Fiddler之iOS手机抓包实战操作
准备工作: 1.Fiddler是否安装 2.笔记本的360免费WiFi即可 步骤: 1.官网下载Fiddler并安装 2.打开Fiddler,点击上方Tools,进入Options,选择HTTPS,按 ...
-
(译)(function (window, document, undefined) {})(window, document); 真正的意思
由于非常感兴趣, 我查询了很多关于IIFE (immediately-invoked function expression)的东西, 如下: (function (window, document, ...