MVC 5 웹 애플리케이션에서 jquery 팝업에서 파일을 업로드해야합니다. 여기에는 MVC 뷰 모델이 들어 있습니다. 나는 대답 한 질문을 here에서 말하고있다. 나는 JQuery와 모달 대화 상자에서이보기를 개방하고MVC 5의 jquery 팝업에서 jQuery Form 플러그인으로 파일 업로드
@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>
을 다음과 같이이 게시물에 따르면 내보기를 정의했습니다.
& 내가 필요한 포스트 액션 메소드가 실행됩니다 만 뷰를 다시로드되지 업로드 버튼을 클릭 & 파일을 선택하면
public ActionResult UploadFile(Common.PatientDocuments Documents, HttpPostedFileBase File)
{
try
{
byte[] data;
using (Stream inputStream = File.InputStream)
{
MemoryStream memoryStream = inputStream as MemoryStream;
if (memoryStream == null)
{
memoryStream = new MemoryStream();
inputStream.CopyTo(memoryStream);
}
data = memoryStream.ToArray();
}
if (data.Length > 0)
{
using (TransactionScope ts = new TransactionScope())
{
string path = string.Empty;
byte[] objContext = null;
DataSet ds = DB.ExecuteDataset("TrustedConnectionString", "pc_ADMReadingFileAdd",
new SqlParameter("@SystemNumber", 1),
new SqlParameter("@FileType", System.IO.Path.GetExtension(File.FileName)),
new SqlParameter("@ReadingID", Documents.hdReadingID),
new SqlParameter("@FileTypeID", Documents.FiltType),
new SqlParameter("@FileName", System.IO.Path.GetFileNameWithoutExtension(File.FileName)),
new SqlParameter("@CustomerID", SessionManager.GetSession().CustomerID));
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
path = Convert.ToString(ds.Tables[0].Rows[0]["FilePath"]);
objContext = (byte[])ds.Tables[0].Rows[0]["TransactionContext"];
SqlFileStream objSqlFileStream = new SqlFileStream(path, objContext, FileAccess.Write);
objSqlFileStream.Write(data, 0, data.Length);
objSqlFileStream.Close();
ts.Complete();
}
}
}
}
catch (Exception expObj)
{
ModelState.AddModelError("Error", "Error occured while uploading file " + expObj.StackTrace);
}
Documents.FileTypeList = Common.GetFileTypes();
return PartialView("~/Views/Shared/PatientDocuments.cshtml", Documents);
}
를 다음과 같이 내 게시물의 액션 메소드는, jqGrid가 새로 업로드 된 파일 레코드를 표시하기 위해 다시로드되지 않습니다.
아무에게도 무슨 일이 일어나고 있는지 알 수 있습니까? & 왜 ajaxForm post 메서드를 성공적으로 실행 한 후 팝업보기가 다시로드되지 않습니다.
는 업로드 된 파일 레코드