开发者

How to upload a image into server folder using fileupload controle in asp.mvc3

开发者 https://www.devze.com 2023-02-27 06:35 出处:网络
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:

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()
0

精彩评论

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