asp.net mvc2 post 文件和来自 flash 的表单值
我们正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了其他尝试做同样事情的人的利益,我们设法使用以下方法使其工作:
这有效,但我不知道为什么,我认为前缀用于访问集合项目或类似的项目。我想在发布文件时,关联的表单数据会在集合中传递?如果有人知道原因或更好的方法,我很乐意为其他人提供答案。
For the benefit of others trying to do the same we managed to get this to work using:
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.