处理2个按钮在一个单一的视图/表格提交行动 - ASP.NET MVC 2 RTM [英] Handling 2 buttons submit Actions in a single View/Form - ASP.NET MVC 2 RTM

查看:312
本文介绍了处理2个按钮在一个单一的视图/表格提交行动 - ASP.NET MVC 2 RTM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图中,用户可以将文件上传到服务器。

I have a View in which the user is able to upload a file to the server.

在这个观点我也有2个按钮:一个上传文件和其他下载的最后一个文件导入

In this view I also have 2 buttons: one to Upload a file and other to Download the last file imported.

在我的控制,我创建2的操作方法:导入和导出

In my Controller I created 2 action methods: Import and Export.

我怎么能管理每个按钮点击到正确的操作方法重定向在我的控制器?

How could I manage to redirect each button click to the proper action method in my Controller?

我曾尝试Html.ActionLink:

I have tried Html.ActionLink:

<%= Html.ActionLink("Upload", "Import", "OracleFile")%>
<%= Html.ActionLink("Download", "Export", "OracleFile")%>

Html.ActionLink没有做的伎俩。动作链接被带我去正确的行动方法,但它们产生的GET请求。这样Request.Files.Count = 0。

Html.ActionLink didn't do the trick. The action links were taking me to the right Action methods but they were generating a GET request. This way Request.Files.Count = 0.

我需要一个POST请求。

I need a POST request.

请注意:最有趣的部分是,上传的是工作,所有这突然停止工作。我见过有些人有与其中Request.Files总是空空的FileUpload任务同样的问题。我认为这是空的,因为你需要一个帖子到服务器。难道不是吗?

Note: the most intriguing part is that the upload was working and all of sudden it stopped working. I've seen that some people are having the same problem with FileUpload tasks in which the Request.Files is always Empty. I think it's empty because you need a post to the server. Isn't it?

推荐答案

也许这将要给你的理念是:

maybe this will give u the idea:

查看

<form enctype="multipart/form-data" method="post" action="/Media/Upload/Photo">
    <input type="file" name="file" id="file" /> 
    <input type="submit"  name= "submitImport" value="Upload" />
    <input type="submit" name = "submitExport"  value="Download" />
</form>

控制器:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Action (FormCollection formCollection)
        {
            if (formCollection["submitImport"] != null)
            {
                return Import(formCollection);
            }
             if (formCollection["submitExport"] != null)
            {
                return Export(formCollection);
            }
        }

导出导入是appropriateactions

the Export and Import are the appropriateactions

这篇关于处理2个按钮在一个单一的视图/表格提交行动 - ASP.NET MVC 2 RTM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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