注:全部要提交的內容包括按鈕都必須在{ }內javascript
在 Visual Basic 和 C# 中,您能夠對 HtmlHelper 類型的任何對象將此方法做爲實例方法調用。在您使用實例方法語法調用此方法時,將忽略第一個參數html
MVC View代碼java
<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> }
在 Visual Basic 和 C# 中,能夠在 HtmlHelper 類型的任何對象上將此方法做爲實例方法來調用。當使用實例方法語法調用此方法時,請省略第一個參數。web
<div class="group-search-box clearfix"> @using (Html.BeginRouteForm("SearchPage", new { cityID = Model.CityID, productType = Model.CurrentProductType, currentPageIndex = Model.CurrentIndex, keyword = Model.keyword }, FormMethod.Get)) { <input type="text" name="keyword" class="search-ipt" value=@Model.keyword> <input type="submit" id="submit" value="搜 索" class="gsearch-btn" > } </div>
直接利用html表單的Aciton屬性進行提交。ajax
方法示例mvc
<form id="askform" action="@Url.Action("AskForm")" method="post"> <div class="title-area-outter clearfix"> <span></span> <select id="dplBDTType" name="dplBDTType"></select> <select id="selType" name="selType"></select> </div> </form>
View 部分app
<div class="issue" id="postWeibo" style="width: 80px"> <a href="javascript:void(0)" class="publish-btn">發佈</a> </div>
Jquery和Ajax部分async
//發佈長微博 $("#postWeibo").click(function () { var blogID = $("#hfID").val(); var title = $("#title").val(); var imgurl = $("#previewImgHide").val(); var des = editor.getContent(); if (title == "") { ShowFailTip('微博標題不能爲空!'); return; } if (title.length >= 40) { ShowFailTip("微博標題不能超出40個字!"); return; } //檢查是否數字 if (isNaN(fee)) { ShowFailTip("不能包含文本必須是數值!"); return; } if (ContainsDisWords(title + des)) { ShowFailTip('您輸入的內容含有禁用詞,請從新輸入!'); return; } $.ajax({ url: "/fx" + $Maticsoft.BasePath + "Blog/AjaxUpdate", type: 'POST', async: false, dataType: 'html', // timeout: 10000, data: { Title: title, CityID: city, Fee: fee, CategoryID: category, Days: days, Tag: tag, startDate: startdate, endDate: enddate, ImgUrl: imgurl, Des: des, BlogID: blogID }, // success: function (resultData) { $(".dialogDiv").hide(); if (resultData == "No") { ShowFailTip("操做失敗,請您重試!"); } else if (resultData == "AA") { $.jBox.tip('管理員不能操做', 'error'); } else { var data = $(resultData); } } }); });
HTML標籤name 和參數名同樣。ide
public ActionResult AskForm(string txtTitle, string txtEditor, string dplBDTType, string selType, string txtYZM) { }
HTML標籤name 屬性和Model屬性保持一致post
[HttpPost] public ActionResult Apply(ViewModel.SNS.Star model) { //邏輯 }
[HttpPost] public ActionResult Apply(FormCollection Form) { //邏輯 }