【发布时间】:2019-10-03 07:57:56
【问题描述】:
我在从另一个视图中使用的局部视图执行操作时遇到问题。
我试过这个用于更改 div 内容的 JQuery
$(document).ready(function () {
//File Upload Button
$(".fileUpload").click(function () {
$.ajax({
type: 'GET',
url: '@Url.Action("FileUpload", "Dashboard")',
data: { type: $(this).attr("data-type") },
success: function (response) {
$(".content").html(response);
},
error: function () {
alert("Problem on uploading file");
}
});
});
});
这是控制器下用于加载局部视图的代码。
public ActionResult FileUpload()
{
return PartialView("~/Views/Dashboard/FileUpload.cshtml");
}
我已设法运行此代码并显示部分视图,但我现在很难从该部分视图执行操作。
我添加了另一个动作Fileload
[HttpPost]
public ActionResult FileLoad()
{
//some codes to execute
}
这将被这个局部视图调用
@model Payout.Models.FundTransfer
@using (Html.BeginForm("FileLoad", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div>
<input type="file" name="Filepath" id="Filepath" />
</div>
<div>
<input type="submit" name="submit" value="Submit" />
</div>
}
现在我不知道执行该操作的最佳方式是什么。你有什么建议吗?
【问题讨论】:
-
你为什么不使用集成在MVC的方式,通过使用AjaxForm...
-
你有样品可以让我按照你说的去做吗?
-
@st_stefanov 您不能将 MVC Ajax 帮助程序用于文件上传。
-
@Mannan Bahelim 如果我尝试仅传递从局部视图获取的文件路径并访问主视图上的文件,该怎么办?有可能吗?如果没有,你有其他选择吗?
标签: c# jquery asp.net-mvc dashboard