0

I have a input div with a form to upload a picture. That works fine! but the input file clears all the other inputs :(

<form action="" method="post" enctype="multipart/form-data">
                <input type="file" name="Image" />
                <br/>
                <input type="submit" value="Upload" />
                <br/>
                <br />
                @if (imagePath != ""){
                <div class="result" style="margin-top:-50px; padding-left:100px">
                <img src="@imageThumbPath" alt="image" />
                <input id="Omsimagefile" value="@newFileName" style="display:block"/>
                </div>
                }
                </form>

With the ajax post will the data updated The file is updated in the map /..

How can i upload the image without page refresh?

Rezise the Image:

 WebImage photo = null;
var newFileName = "";
var imagePath = "";
var imageThumbPath = "";

if (IsPost)
    {
    photo = WebImage.GetImageFromRequest();
    if (photo != null)
        {
        newFileName = Path.GetFileName(photo.FileName);
        imagePath = @"/Images/OmsObject/" + newFileName;
        photo.Resize(width: 400, height: 300, preserveAspectRatio: true,
        preventEnlarge: true);
        photo.Save(@"~/" + imagePath);

        imageThumbPath = @"/Images/OmsObject/Thump/" + newFileName;
        photo.Resize(width: 120, height: 80, preserveAspectRatio: true,
           preventEnlarge: true);
        photo.Save(@"~/" + imageThumbPath);
        }
    }
Bram
  • 49
  • 2
  • 11
  • you can find the answer here: http://stackoverflow.com/questions/19042116/ajax-beginform-in-mvc-to-upload-files-by-using-example-on-stackoverflow/19044689#19044689 – Ashwini Verma Jan 03 '14 at 06:23
  • Thanks for this ! How do i rezise the files? (update the question..) – Bram Jan 03 '14 at 09:47

1 Answers1

0

I'm not sure if this might be of help or if you'd be able to use this but I believe a package like http://www.uploadify.com/ would greatly help you here. They have both HTML5 and Flash versions and support ajax upload so that you can upload the file and have it waiting for you when you submit the form. Hope this helps!!

hjavaher
  • 2,589
  • 3
  • 30
  • 52