开发者

File upload in asp.net mvc using ajax

开发者 https://www.devze.com 2022-12-27 16:54 出处:网络
I have a sim开发者_运维百科ple html form with two controls: input-text and input-file I need to write an ajax query (using jquery is better) to send data (file and value from text field to mvc acton

I have a sim开发者_运维百科ple html form with two controls:

input-text and input-file

I need to write an ajax query (using jquery is better) to send data (file and value from text field to mvc acton)

I wrote

$.ajax({
    type: "POST",
    url: "/controller/acton",
    enctype: 'multipart/form-data',
    data: 'text=' + $("#text").val() + '&file=' + $("#file").val()
... 

and in controller:

 [HttpPost]
  public ActionResult StoreItem(FormCollection forms)
  {
     foreach (string inputTagName in Request.Files)
  ...

this returns null in Request.


http://www.plupload.com is awesome


You can't POST a file using only javascript.

Look at http://www.uploadify.com/ or something like http://www.swfupload.org/

0

精彩评论

暂无评论...
验证码 换一张
取 消