これは私のコントローラーです:
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");
}
これは私の見解です:
@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>
}
私の質問: 「作成」ボタンを押すと、Web ページに以下が表示されます。
接続がリセットされました。
ページの読み込み中にサーバーへの接続がリセットされました。
サイトが一時的に利用できないか、混雑している可能性があります。しばらくしてからもう一度お試しください。どのページも読み込めない場合は、コンピュータのネットワーク接続を確認してください。コンピュータまたはネットワークがファイアウォールまたはプロキシによって保護されている場合は、Firefox が Web へのアクセスを許可されていることを確認してください。
Razor View でデバッグを試み、この Web サイトを検索すると、Web サイトに表示されたとおりに実行されましたが、わかりません。私を助けてください。