asp.net mvc2 post 文件和来自 flash 的表单值

发布于 2024-10-11 00:58:55 字数 810 浏览 1 评论 0原文

我们正在尝试从 Flash 应用程序上传文件并将参数提交到 ASP.Net MVC2 控制器。本质上,这只是使用文件和发布的参数创建标准的多部分/表单帖子。

在控制器中:

public string Upload(HttpPostedFile file, string someString, 
                        int someInt, DateTime someDate)
{
    // some code
   return "success";
}

从 flash(flex) 中:

var file : FileReference = "C:\someFile.txt";
var urlRequest: URLRequest = new URLRequest("http://localhost/MySite/Uploader/Upload");
urlRequest.method = URLRequestMethod.POST;

var variables:URLVariables = new URLVariables();
variables.someString = "test";
variables.someInt= 1;
variables.someDate = "01/01/2011 00:00:00";

urlRequest.data = variables;

file.upload( urlRequest, "file" );

控制器已实例化,但未找到该方法,如果我们只是发布没有附加参数的文件,它可以正常工作,我们还可以让它与文件和 someInt 一起使用参数但没有别的?

We're trying to upload a file and submit parameters to an ASP.Net MVC2 controller from a flash application. Essentially though this is simply creating a standard multipart/form post with a file and posted params.

In the controller:

public string Upload(HttpPostedFile file, string someString, 
                        int someInt, DateTime someDate)
{
    // some code
   return "success";
}

And from flash(flex):

var file : FileReference = "C:\someFile.txt";
var urlRequest: URLRequest = new URLRequest("http://localhost/MySite/Uploader/Upload");
urlRequest.method = URLRequestMethod.POST;

var variables:URLVariables = new URLVariables();
variables.someString = "test";
variables.someInt= 1;
variables.someDate = "01/01/2011 00:00:00";

urlRequest.data = variables;

file.upload( urlRequest, "file" );

The controller is instantiated but the method isn't found, if we just post the file without the additional params it works fine and we can also get it to work with the file and the someInt param but nothing else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2024-10-18 00:58:55

为了其他尝试做同样事情的人的利益,我们设法使用以下方法使其工作:

[HttpPost]
public int Index(HttpPostedFileBase file,
    [Bind(Prefix = "someString")] string someString,
    [Bind(Prefix = "someInt")] int someInt,
    [Bind(Prefix = "someDate")]  string someDate)
{
    // stuff here
}

这有效,但我不知道为什么,我认为前缀用于访问集合项目或类似的项目。我想在发布文件时,关联的表单数据会在集合中传递?如果有人知道原因或更好的方法,我很乐意为其他人提供答案。

For the benefit of others trying to do the same we managed to get this to work using:

[HttpPost]
public int Index(HttpPostedFileBase file,
    [Bind(Prefix = "someString")] string someString,
    [Bind(Prefix = "someInt")] int someInt,
    [Bind(Prefix = "someDate")]  string someDate)
{
    // stuff here
}

This works but I've no idea why, I thought prefixes were for accessing collection items or some such. I guess when posting a file the associated form data is passed in a collection? If anyone knows why or a better approach I'm happy to give the answer to someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文