Could you please tell me how 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...
1 Answer
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()
10 Comments
Victor
Thank You so much Maidot it is working fine what i'm expecting.How Can i get textbox values using FormCollection[] form ?
Victor
Ok ,Thank you again i'm using FormCollection objformCollection to get textbox values now it is working fine ,U have done good job thank you so much......
Maidot
I am so glad that can help you~ :)
Victor
Hi can you give any idea how to bind the dropdownlist from database in mvc please...
Maidot
Can you give me the datastructure(Model) of the data you want to bind so I can help you, or some code more better~
|