This is my Controller:
public ActionResult Create()
{
ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName");
return View();
}
//
// POST: /ManagePhotos/Create
[HttpPost]
public ActionResult Create(Photo photo, HttpPostedFile file)
{
if (ModelState.IsValid)
{
if (file != null && file.ContentLength > 0)
{
// save as original size of image
var newfileName = Guid.NewGuid().ToString() + "_"
+ Path.GetFileName(file.FileName);
var bigImagePath = Path.Combine(Server.MapPath("~/Content/PublicPhotos/BigImages"), newfileName);
file.SaveAs(bigImagePath);
// save as thumbnail image
var photoUploaded = new WebImage(bigImagePath);
photoUploaded.Resize(width: 200, height: 150, preserveAspectRatio: true, preventEnlarge: true);
var thumbImagePath = Path.Combine(Server.MapPath("~/Content/PublicPhotos/ThumbImages"), newfileName);
photoUploaded.Save(thumbImagePath);
}
db.Photos.Add(photo);
db.SaveChanges();
return RedirectToAction("Index");
}
This is my View:
@using (Html.BeginForm("Create","ManagePhotos", FormMethod.Post, new {enctype = "multipart/form-data"}))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Photo</legend>
<div class="editor-label">
@Html.LabelFor(model => model.CategoryID, "Category")
</div>
<div class="editor-field">
@Html.DropDownList("CategoryID", String.Empty)
@Html.ValidationMessageFor(model => model.CategoryID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.Label("File name: ")
</div>
<div class="editor-field">
<input type="file" name="file"/>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
My Question: When I press "Create" button , the webpage show me below:
The connection was reset.
The connection to the server was reset while the page was loading.
The site could be temporarily unavailable or too busy. Try again in a few moments. If you are unable to load any pages, check your computer's network connection. If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
I try to debug in Razor View , and lookup on this website and I did exactly the website showed me but I cannot figure at out. Please help me.