Jquery MVC ajax表单后期反序列化问题
我试图发布一个formenctype=multipart/formdata的表单,其中包含一个模型和fileHttpPostedFileWrapper,当得到响应时,将返回整个页面,而不仅仅是更新的部分视图 表格:Jquery MVC ajax表单后期反序列化问题,jquery,ajax,asp.net-mvc,asp.net-mvc-4,Jquery,Ajax,Asp.net Mvc,Asp.net Mvc 4,我试图发布一个formenctype=multipart/formdata的表单,其中包含一个模型和fileHttpPostedFileWrapper,当得到响应时,将返回整个页面,而不仅仅是更新的部分视图 表格: 服务器代码在哪里?我已经更新了这些详细信息,现在可能会重复 <textarea rows="3" id="Message" name="Message" placeholder="Write a reply..."> </textarea>
服务器代码在哪里?我已经更新了这些详细信息,现在可能会重复
<textarea rows="3" id="Message" name="Message" placeholder="Write a reply..."> </textarea>
<button id="btnNewComment" type="submit" class="btn btn-success"><i class="icon-envelope"></i> Send</button>
<label class="control-label">Attach a file:</label>
<input type="file" name="postedFile" id="postedFile">
</form>
<div id="list">@Html.Partial("View", Model)</div>
<script>
$(function () {
var options = {
target: '#list',
beforeSubmit: showRequest, // pre-submit callback
success: showResponse, // post-submit callback
error: function (err) {
alert(err)
},
};
// bind to the form's submit event
$('#myForm').submit(function () {
$(this).ajaxSubmit(options);
return false;
});
});
// pre-submit callback
function showRequest(formData, jqForm, options) {
var queryString = $.param(formData);
alert('About to submit: \n\n' + queryString);
return true;
}
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
'\n\nThe output div should have already been updated with the responseText.');
}
//
// POST: /Create
[HttpPost]
public ActionResult Index(Model thread, HttpPostedFileWrapper postedFile)
{
if (ModelState.IsValid)
{
try
{
var model = (Class)Shared.SelectedConversation;
model.Create(thread, postedFile);
return View("View", model);
}
catch (Exception ex)
{
while (ex.InnerException != null)
ex = ex.InnerException;
ModelState.AddModelError("Error", ex.Message);
}
}
return View();
}