Mike,
Hopefully this is a worthy question.
Within the Classifieds Tutorial, I'd like to add an Image upload/display
routine to the SELL.cshtml page. I'm basically using the code attached.
Would you suggest a double SUBMIT routine or a Jscript/JQuery to download/display the image.
I shouldn't save the image untill i'm saving the new Item record, correct?
Naturally, I will use a Pictures table to store: Id,ItemId,FileName, date/time,
saved/updated when saving the item record.
(? multiple pics and then show it/them on the Display Item function, for later....) ..One step at a time...
I was using a "button" with a
JS function() but it got ugly...and errors..
Thanks,
Edgy in Dallas
***************************************
Code:
@{ WebImage photo = null;
var newFileName = "";
var imagePath = "";
if(IsPost){
photo = WebImage.GetImageFromRequest();
if(photo != null){
newFileName = Guid.NewGuid().ToString() + "_" +
Path.GetFileName(photo.FileName);
imagePath = @"images\" + newFileName;
photo.Save(@"~\" + imagePath);
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<fieldset>
<legend> Upload Image </legend>
<label for="Image">Image</label>
<input type="file" name="Image" />
<br/>
<input type="submit" value="Upload" />
</fieldset>
</form>
<h1>Uploaded Image</h1>
@if(imagePath != ""){
<div class="result">
<img src="@imagePath" alt="image" />
</div>
}
</body>
</html>