Asp.net MVC-fileupload 值在 httppost 方法中显示空值

在视图上:


<div id="project-contact-form">

                @using (Ajax.BeginForm("Apply","Careers", new AjaxOptions { OnSuccess = "onApplySuccess" }, new { @id = "form1", @enctype = "multipart/form-data" }))

                {

                <div class="row">

                    <div class="col-md-12">

                        <div id="success-project-contact-form" class="no-margin-lr"></div>

                    </div>

                    <div class="col-md-6">

                        <input type="text" required name="Firstname" id="Firstname" placeholder="First name" class="big-input">

                    </div>

                    <div class="col-md-6">

                        <input type="text" required name="Lastname" id="Lastname" placeholder="Last name" class="big-input">

                    </div>

                    <div class="col-md-6">

                        <input type="email" required name="Email" id="email" placeholder="E-mail" class="big-input">

                    </div>

                    <div class="col-md-6">

                        <input type="text" required name="Mobile" id="mobile" placeholder="Mobile" class="big-input">

                    </div>

                    <div class="col-md-6">

                    

                        <input type="file" name="FileUploader" id="files" class="hidden" />

                        <label for="files" class="float-left cursor-pointer">Upload CV</label>

                    </div>

                    <div class="col-md-12 text-center">

                        <button id="project-contact-us-button" type="submit" class="btn btn-medium btn-transparent-bnsights btn-rounded md-margin-15px-bottom sm-display-table sm-margin-lr-auto">Send</button>

                    </div>

                </div>

                }


            </div>


胡说叔叔
浏览 154回答 1
1回答

呼啦一阵风

通常你不能使用Ajax.BeginForm()like上传文件Html.BeginForm()。您必须使用 JavaScript/jQuery 来提交表单元素。这是解决方案:$(document).ready(function(){&nbsp; &nbsp; $(document).on("submit", "#form1", function (event) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.preventDefault();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.stopImmediatePropagation();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var formData = new FormData(this);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var url = this[0].action;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: url,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: 'POST',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: formData,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function (response) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (response) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //do necessary work with response&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error: function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //handle error here&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cache: false,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contentType: false,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; processData: false&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP