本文介绍了调用Post方法时出现Razor Page问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个.cshtml文件,它是.cs文件。我正在使用Razor Pages。我正在使用DropZone上传文件。表单中的操作未命中.cs页面中的方法。我搞不懂为什么.cs文件中的代码没有命中。我使用了断点,但它似乎从未到达C#代码。 有没有人看到我做错了什么?-----------
@page
@model SipiARPortal.Pages.SystemAdmin.AdminUsersModel
@inject IVendor _vendor
@{
ViewData["Title"] = "Admin File Upload";
ViewData["Header"] = new PageHeader()
{
Title = "ADMIN FILE UPLOAD",
SubTitle = "Upload Files here",
Breadcrumbs = new List<Breadcrumb>() {
new Breadcrumb() { Name = "Admin File Uplaod", URL = "/systemadmin/adminfileupload" }
}
};
}
<link href="~/css/dropzone.css" rel="stylesheet" />
<div class="card shadow-sm mb-5">
<div class="card-body">
<div class="row">
<form action="/systemadmin/adminfileupload" method="post"
class="dropzone" enctype="multipart/form-data"
id="my-dropzone">
</form>
</div>
<div class="row mg-t-5">
<div id="verification" class="col-12"></div>
</div>
</div>
</div>
@section Scripts {
<script src="~/lib/dropzone/dropzone.js"></script>
<script type="text/javascript">
var gridObj = null;
Dropzone.options.myDropzone = {
createImageThumbnails: false,
acceptedFiles:'',
allowedExtensions: '.pdf,.zip',
dictDefaultMessage: 'Drop results file here for verification',
init: function () {
this.on("success", function (file, data) {
magalert.ajaxMessage(data);
if (data.success) {
if (gridObj !== null) {
$("#Grid").ejGrid("destroy");
}
gridObj = $("#verification").ejGrid({
dataSource: data.data,
allowPaging: true,
allowSorting: true,
isResponsive: true,
allowFiltering: true,
enableHeaderHover: true,
filterSettings: { filterType: "excel" },
columns: [
{ field: "filename", headerText: "FileName", width: 275 },
]
});
var target = $('#verification');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
}
}
e
});
}
};
</script>
}
---------
namespace SipiARPortal.Pages.SystemAdmin
{
[Authorize(Roles = "SystemAdmin,SipiAdmin")]
public class AdminFileUploadsModel : PageModel
{
private readonly ILogger<AdminUsersModel> _logger;
private readonly UserManager<ApplicationUser> _userManager;
public readonly IAzureBlob _blob;
private readonly ApplicationDbContext _db;
private readonly ConfigurationDbContext _cdb;
public async Task OnPostAsync(IFormFile UploadFiles)
{
await _blob.SaveFileStream(UploadFiles.OpenReadStream(), "pending", UploadFiles.FileName);
}
[HttpPost]
public async Task<IActionResult> ResultsUpload(IFormFile UploadFiles)
{
ServiceResult<List<ResultIssue>> retVal = new ServiceResult<List<ResultIssue>>() { Data = new List<ResultIssue>(), Success = true };
try
{
await _blob.SaveFileStream(UploadFiles.OpenReadStream(), "pending", UploadFiles.FileName);
//var blobStream = await _blob.GetFileStream(blob, sigFileName);
}
catch (Exception ex)
{
_logger.LogError(ex, "Results Upload");
retVal.Message = "Error parsing results file - did you select the correct format?";
retVal.Success = false;
}
return new JsonResult(retVal);
}
}
}
推荐答案
请求URL应为
/systemadmin/adminfileuploads
,您错过了s
。默认情况下,在Razor页面中启用防伪令牌验证。您需要使用表单中的
@Html.AntiForgeryToken()
手动添加。<form action="/systemadmin/adminfileuploads" method="post" class="dropzone" enctype="multipart/form-data" id="my-dropzone"> @Html.AntiForgeryToken() </form>
这篇关于调用Post方法时出现Razor Page问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!