码迷,mamicode.com
首页 > Web开发 > 详细

Mvc利用Html.BeginForm 提交表单代码详解

时间:2015-05-07 14:12:43      阅读:633      评论:0      收藏:0      [点我收藏+]

标签:

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)
        {
//逻辑
}

 

Mvc利用Html.BeginForm 提交表单代码详解

标签:

原文地址:http://www.cnblogs.com/sunxi/p/4484440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!