ASP.NET MVC:捕获下载提示的结果 [英] ASP.NET MVC : capture result of download prompt

查看:114
本文介绍了ASP.NET MVC:捕获下载提示的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可使文件可用,并提示用户使用open/download/cancel.我想如果文件已打开或下载,但要如果取消则不采取行动.

I have a bit of code that makes a file available and prompts user to open/download/cancel. I would like to take an action if the file is opened or downloaded, but not if canceled.

这是从控制器下载的行:

This is the download line, from the controller :

return File(fileAsBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);

我想我的问题是,如何从该操作中获取返回值?我会在控制器或调用它的视图中看到结果吗?

I guess my question is, how do I capture a return value from this action? Would I see the result in the controller or in the view that calls it?

我是一个挣扎的新手.不要假设基础知识.

I'm a struggling newbie. Don't assume foundational knowledge.

谢谢.

推荐答案

您的控制器:

public class HomeController : Controller
{
    [HttpPost]
    public ActionResult Upload(string SubmitButton, HttpPostedFileBase file)
    {
        if (SubmitButton == "Cancel")
        {
            //redirect to a cancel page
            //return RedirectToAction("Index", "Home");
        }

        //put a breakpoint in this metho to interogate file, 
        //the file you are going to save to db or do something with

        return View();
    }

    public ActionResult Tut115()
    {
        return View();
    }

您的视图:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Tut115</title>
</head>
<body>
    <div>
        @using (Html.BeginForm("Upload",
        "Home",
        FormMethod.Post,
        new { enctype = "multipart/form-data" }))
        {
            <input type="file" name="file" id="file" /><br>
            <input type="submit" name="SubmitButton" value="Cancel" />
            <input type="submit" name="SubmitButton" value="Upload" />
        }
    </div>
</body>
</html>

这篇关于ASP.NET MVC:捕获下载提示的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆