[英]C#/ASP.NET ActionLink/Functions/Wrong Linking
用户上传文件,然后由医生检查。 然后,医生上传他的文件,说明他们的评论,然后用户可以阅读该文件。 至少,他们应该能够。 当医生上传文件时,将在用户文件夹中创建一个新目录,并将该项目上传到该文件夹中。
现在的错误。 在详细信息页面上,用户看到有一个文件链接可供下载,因此他们可以阅读医生的笔记。 但是,当他们单击链接时,该链接会返回404。我们发现,如果我们从Review文件夹中删除文件并将其放在主用户目录中,则该链接现在可以使用。 显然,该链接未指向正确的位置,但是正如我所不知道的.NET或C#一样,这已被证明很烦人。
这是来自Details.cshtml页面的原始代码的一部分:
<table>
<tr>
<th colspan="4" class="display-label">Uploaded Documents</th>
</tr>
<tr>
<th>FileName</th>
<th>Download Files</th>
</tr>
@foreach (var file in ((IEnumerable<MyCombinedQueryModel>)ViewBag.Files))
{<tr>
<td>
@Html.ActionLink("Download", "Download", new { id = Model.PatientsId, name = file.FileName })
</td>
<td>
@file.FileName
</td>
</tr>
}<tr>
<th colspan="4" class="display-label">Download reviewer suggestion document</th></tr>
<tr>
<th>FileName</th>
<th>Download Files</th>
</tr>
@if(Model.reviewed)
{
foreach (var file in ((IEnumerable<MyCombinedQueryModel>) ViewBag.Path))
{
<tr>
<td>
@Html.ActionLink("Download", "Download", new {id = Model.PatientsId, name = file.FileName})
</td>
<td>
@file.FileName
</td>
</tr>
}
}
</table>
还有来自DoctorsController.cs的部分
//Download files string names
public ActionResult Download(int? id, string name)
{
string fileName = name;
var uploads = (from u in _db.Patients
where u.PatientsId == id
select u.FilesUrl).FirstOrDefault();
if (uploads != null)
{
string folder = Path.GetFullPath(uploads);
//HttpContext.Response.AddHeader("content-dispostion", "attachment; filename=" + fileName);
return File(new FileStream(folder +"/" + fileName, FileMode.Open), "content-dispostion", fileName);
}
throw new ArgumentException("Invalid file name of file not exist");
}
现在,在我们的数据库中,我们有两个字段,FilesUrl和PathUrl。 PathUrl在Review文件夹中保存Reviewed文件的URL。 我认为,如果我正确的话,那是他们两个都在调用仅链接到FileUrl的同一函数(下载)。 我尝试在详细信息页面中将审阅部分中的actionLink更改为“ DownloadR”,然后复制并粘贴了Download函数(将其重命名为DownloadR并更改为查找PathUrl),但仍无法正常工作。
是否有人在这里看到任何问题或有关如何解决的建议? 预先感谢您的宝贵时间!
似乎是FilesUrl与PathUrl的问题。 如果患者上传的文件和Dr上传的文件位于不同的目录中,则此控制器方法将无法同时使用。
我要在Download方法中添加第三个参数,该参数指定要下载的文件是来自Dr还是患者。
public ActionResult Download(int? id, string name, bool reviewDirectory)
...
var uploads = (from u in _db.Patients
where u.PatientsId == id
select (reviewDirectory ? u.PathUrl : u.FilesUrl)).FirstOrDefault();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.