私はMVC3を使用していますが、次のコードのコントローラーがあります。ViewModel[HttpPost] ActionResultを取得できません。AdvSlotDeleteViewModelの結果をNULLで削除します。同様の編集用アクションメソッドがあり、機能しています。この問題について教えてください。 ?
// GET: /ManageAdvSlots/Delete/5
public ActionResult Delete(int id)
{
AdvSlot advSlot = advSlotRepository.FindById(id);
AdvSlotDeleteViewModel deleteViewModel = Mapper.Map<AdvSlot, AdvSlotDeleteViewModel>(advSlot);
return View(deleteViewModel);
}
//
// POST: /ManageAdvSlots/Delete/5
[HttpPost]
public ActionResult Delete(AdvSlotDeleteViewModel deleteViewModel)
{
if (ModelState.IsValid)
{
AdvSlot advSlot = Mapper.Map<AdvSlotDeleteViewModel, AdvSlot>(deleteViewModel);
advSlotRepository.Delete(advSlot.AdvSlotId);
advSlotRepository.Save();
}
return RedirectToAction("Index");
}
}
見る
@model MyProject.ViewModels.AdvSlotDeleteViewModel
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<fieldset>
<legend>AdvSlotDeleteViewModel</legend>
<div class="display-label">AdvSlotId</div>
<div class="display-field">
@Html.DisplayFor(model => model.AdvSlotId)
</div>
<div class="display-label">Name</div>
<div class="display-field">
@Html.DisplayFor(model => model.Name)
</div>
<div class="display-label">Description</div>
<div class="display-field">
@Html.DisplayFor(model => model.Description)
</div>
<div class="display-label">IsPublished</div>
<div class="display-field">
@Html.DisplayFor(model => model.IsPublished)
</div>
<div class="display-label">Code</div>
<div class="display-field">
@Html.DisplayFor(model => model.Code)
</div>
<div class="display-label">Note</div>
<div class="display-field">
@Html.DisplayFor(model => model.Note)
</div>
</fieldset>
@using (Html.BeginForm()) {
<p>
<input type="submit" value="Delete" /> |
@Html.ActionLink("Back to List", "Index")
</p>
}
モデルを見る
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MyProject.ViewModels
{
public class AdvSlotDeleteViewModel
{
public int AdvSlotId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsPublished { get; set; }
public string Code { get; set; }
public string Note { get; set; }
}
}