Mvc利用Html.BeginForm 提交表单代码详解
js验证表单数据合法性代码
$(function () { $("#btnApplication").click(function () { var imageurl = $("#SXtPhoto").val(); var desc = $("#tDesc").val(); var type = $("#type").val(); if (imageurl == "") { alert("请上传照片!"); return; } if (desc == "") { alert("请填写自荐理由!"); return; } if (type == 0) { alert("请选择达人类型!"); return; } $(this).attr("disabled", "disabled"); // $("form:last").submit(); $(".MyForm").submit();//提交表格 }); });
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> }
MVC Controller代码
第一种写法
[HttpPost] public ActionResult Apply(ViewModel.SNS.Star model) { //逻辑 }
第二种写法
[HttpPost] public ActionResult Apply(FormCollection Form) { //逻辑 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。