一,MVC HtmlHelper方法
-
Html.BeginForm(actionName,controllerName,method,htmlAttributes){}
-
BeginRouteForm 方法 (HtmlHelper, String, Object, FormMethod)
二,传统Form表单Aciton属性提交
三,Jquery+Ajax 提交表单
四,MVC Controller控制器和表单参数传递
MVC HtmlHelper方法
一,Html.BeginForm(actionName,controllerName,method,htmlAttributes){}
注:所有要提交的内容包括按钮都必须在{ }内
参数
htmlHelper
类型:System.Web.Mvc.HtmlHelper
此方法扩展的 HTML 帮助器实例。
actionName
类型:System.String
操作方法的名称。
controllerName
类型:System.String
控制器的名称。
routeValues
类型:System.Object
一个包含路由参数的对象。 通过检查对象的属性,利用反射检索参数。 此对象通常是使用对象初始值设定项语法创建的。
method
类型:System.Web.Mvc.FormMethod
用于处理窗体的 HTTP 方法(GET 或 POST)。
htmlAttributes
类型:System.Object
一个对象,其中包含要为该元素设置的 HTML 特性。
返回值
类型:System.Web.Mvc.Html.MvcForm
<form> 开始标记。
Html.BeginForm 方法示例
MVC View代码
<h1>在线申请</h1>
@using (Html.BeginForm("Apply", "Star", FormMethod.Post, new {@class="MyForm"}))
{
<div class="application_b_3">
<table width="820" border="0">
<tr>
<td width="80" height="50">达人类型</td>
<td width="730">
@Html.DropDownListFor(m => m.StarModel.TypeID, Model.DropList, new { id = "type", @class = "my-" })
</td>
</tr>
<tr>
<td height="50">首页达人照</td>
<td>
<div class="picture_an" id="UploadPhoto" style="width: 142px">
<a href="javascript:void(0);" class="btn_addPic"><span><em>+</em>上传照片</span>
<input tabindex="3" title="支持jpg、jpeg、gif、png格式,文件小于5M" size="3" name="pic" id="absFileInput" class="filePrew" type="file" />
</a>
</div>
</td>
</tr>
<tr>
<td height="50"></td>
<td>
@Html.HiddenFor(m => m.StarModel.UserGravatar, new { id = "SXtPhoto" })
<img src="" id="imgPhoto" height="176px" />
</td>
</tr>
<tr>
<td height="100">自荐理由</td>
<td>
@Html.TextAreaFor(m => m.StarModel.ApplyReason, new { id = "tDesc" })
</td>
</tr>
<tr>
<td height="50"></td>
<td>
<a href=" javascript:void(0)" id="btnApplication"><img src="@Url.Content("~/Areas/SNS/Themes/Default/Content/images/ap_9.gif")" alt="" /></a>
</td>
</tr>
</table>
</div>
}