Could you please tell me how开发者_JAVA百科 can i save the image into server path image folder when i upload a image using file upload controle in asp.mvc3 .please help me...
View:
<% using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{ %>
<div class="uploadfiles">
<p><input type="file" name="files" /></p>
</div>
<a href="#add" id="additem">Add files</a><br />
<input type="submit" value="Yes" />
<% } %>
<script type="text/javascript">
$('#additem').live('click', function () {
$('.uploadfiles').append($("<p><input type='file' name='files' /></p>"));
});
</script>
Controller:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(FormCollection[] form)
{
for (int fileIndex = 0; fileIndex < Request.Files.Count; fileIndex++)
{
//let upload file to App_Data folder
Request.Files[fileIndex].SaveAs(Server.MapPath("/App_Data/" + Request.Files[fileIndex].FileName));
}
return View();
}
It's depend the name of textbox, for example if there is an input in View like:
<input name="yourname" type="text" />
then you can get the value in Controller use:
var textBoxValue = formCollection["yourname"].ToString()
精彩评论