1

私は私のビューにこのフォームを持っています: 私の見解

私のコントローラーには、次のメソッドがあります。

 [HttpPost]
 public ActionResult UploadFile(HttpPostedFileBase file)
{
// ...
}

ファイルをアップロードするためにクリックされた入力タグの ID を取得するにはどうすればよいですか? (id=1 または id=2?

ありがとうございました!!!

4

2 に答える 2

1

Id is only used to identify the html element on the page, not for submitting to the server. If you don't need to manipulate the data on the client, you even don't need to specify id. By specifying the same name, you can "stack" the files.

So

<form action="/action" enctype="multipart/form-data" method="post">
   <input name="file" type="file"></input>
   <input name="file" type="file"></input>
</form>

In your controller you receive an array of files.

[HttpPost]
 public ActionResult UploadFile(HttpPostedFileBase[] file)
{
// ...
}
于 2012-12-26T19:55:40.930 に答える
0
<script src="INCLUDE JQUERY"></script>
<script>
$(function(){
$('input[type="file"]').click(){
 $('#id').value = $(this).attr('id');
}
})
function fillId(){}
</script>
<form>

<input type="text" id="id" name="id"/>
<input type="file" id="file1"/>
<input type="file" id="file2"/>
<input type="Submit" value="submit"/>
</form>

*NOTE-this night not be the final code but you get the idea

于 2012-12-26T19:55:47.950 に答える