0
我有以下看法:MVC:如何:一個按鈕點擊無需離開當前的形式
@if (!string.IsNullOrWhiteSpace(ptiFileName))
{
<span style="font-style:italic">
<a href="@Url.Action("DownloadPtiDocument", "Project")" style="text-decoration:underline">@ptiFileName</a>
<a class="glyphicon glyphicon-trash" href="@Url.Action("DeletePtiDocument", "Project")" type=""></a>
</span>
}
爲DownloadPtiDocument控制器正常工作時的文件名鏈接,用戶點擊:
[Route("project/download/{id:int}")]
public async Task<ActionResult> DownloadPtiDocument(int id)
{
var ptiFile = ProjectRepository.GetById(id.ToString()) as Project;
if (ptiFile.PtiUploadDocuments == null)
return HttpNotFound();
var info = await S3Helpers.DownloadFile(ptiFile.PtiUploadDocuments.S3Bucket, ptiFile.PtiUploadDocuments.S3FileName);
if (info != null)
return new FileStreamResult(info.Stream, info.ContentType) { FileDownloadName = ptiFile.PtiUploadDocuments.FileName };
return HttpNotFound();
}
但我不知道如何聲明函數DeletePtiDocument其中用戶將停留在當前屏幕上,而我執行一些邏輯來刪除我的模型中的數據。
這裏是接口。點擊圖標「glyphicon glyphicon-trash」應該在我的控制器上執行一些操作,而無需刷新或離開當前屏幕。這可能嗎?
使它成爲阿賈克斯呼叫。 – dansasu11
要在不離開當前頁面的情況下發出HTTP請求,它將是由JavaScript代碼構成的AJAX請求。 – David
不幸的是,我不熟悉JavaScript,如果你可以指點我正確的方向或教程,我需要看看。這將非常感激。 – JADE