Javascript 使用jquery表单插件从MVC5中的jquery弹出窗口上传文件
在我的MVC5Web应用程序中,我需要从jquery弹出窗口上传文件;其中包含MVC视图模型。我指的是我的回答。根据这篇文章,我将我的观点定义如下Javascript 使用jquery表单插件从MVC5中的jquery弹出窗口上传文件,javascript,jquery,ajax,asp.net-mvc,Javascript,Jquery,Ajax,Asp.net Mvc,在我的MVC5Web应用程序中,我需要从jquery弹出窗口上传文件;其中包含MVC视图模型。我指的是我的回答。根据这篇文章,我将我的观点定义如下 @using VirtuOx.Views.Shared.Resources @model VirtuOx.Models.Common.PatientDocuments @{ Layout = "~/Views/Shared/_LayoutBlank.cshtml"; } <script src="@Url.Content("~/Scri
@using VirtuOx.Views.Shared.Resources
@model VirtuOx.Models.Common.PatientDocuments
@{
Layout = "~/Views/Shared/_LayoutBlank.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.form.js")" type="text/javascript"></script>
@using (Html.BeginForm("UploadFile", "Common", FormMethod.Post, new { id = "frmReadingFiles", enctype = "multipart/form-data" }))
{
@Html.ValidationSummary();
@Html.HiddenFor(m => m.HideDelete)
@Html.HiddenFor(m => m.HideUpload)
<table>
<tr>
<td class="align_right" style="width:20%;">@Html.LabelFor(m => m.hdReadingID)</td>
<td>@Html.DisplayFor(m => m.hdReadingID)@Html.HiddenFor(m => m.hdReadingID)</td>
</tr>
<tr>
<td class="align_right">@Html.LabelFor(m => m.PatientName)</td>
<td>@Html.DisplayFor(m => m.PatientName)@Html.HiddenFor(m => m.PatientName)</td>
</tr>
@if (Model.HideUpload == "False")
{
<tr>
<td class="align_right">@Html.LabelFor(m => m.FiltType)</td>
<td>@Html.DropDownListFor(m => m.FiltType, new SelectList(Model.FileTypeList, "Value", "Text"), new { @class = "chzn-select-no-single" })</td>
</tr>
<tr>
<td class="align_right">@Html.LabelFor(m => m.File)</td>
<td>@Html.TextBoxFor(m => m.File, new { type = "file", name = "File[0]" })</td>
</tr>
}
</table>
if (Model.HideUpload == "False")
{
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<input type="submit" class="btn blue" id="btnUpload" value='@VirtuOxCommon.PatientDocuments_Button_Upload' />
<input type="button" class="btn blue" id="PatientDocuments_btnClose" value="@VirtuOxCommon.PatientDocuments_Button_Close" />
</div>
</div>
}
}
@{Html.RenderPartial("_PatientDocuments", new ViewDataDictionary { { "ReadingID", Model.hdReadingID }, { "HideDelete", Model.HideDelete } }); }
@if (Model.HideUpload == "True")
{
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<input type="button" class="btn blue" id="PatientDocuments_btnClose" value="@VirtuOxCommon.PatientDocuments_Button_Close" />
</div>
</div>
}
<script type="text/javascript">
$(document).ready(function () {
$('#frmReadingFiles').ajaxForm({});
$("#PatientDocuments_btnClose").click(function (e) {
$(this).parents("div").find(".ui-dialog-content").dialog('close');
});
});
</script>
当我选择文件并单击上载按钮时,将执行所需的post-action方法,但不会重新加载视图;这导致弹出窗口上的jqGrid不会重新加载以显示新上载的文件记录
有人能告诉我流中发生了什么错误吗&为什么在成功执行ajaxForm post方法后没有重新加载弹出视图
请注意,成功执行post方法后,弹出窗口将保持其在浏览器中的状态&当我关闭并重新打开它时,它将显示带有上载文件记录的jqGrid
有谁能告诉我流程中发生了什么错误&为什么弹出窗口
成功执行ajaxForm post后不会重新加载视图
方法
因为您所展示的内容中没有可以重新加载它的代码
如果希望发生这种情况,可以订阅AJAX调用的成功回调并重新加载视图的任何部分:
$('#frmReadingFiles').ajaxForm(function(result) {
// Inject the result in the desired portion of your DOM:
$('#some_container_id').html(result);
});
$('#frmReadingFiles').ajaxForm(function(result) {
// Inject the result in the desired portion of your DOM:
$('#some_container_id').html(result);
});