元のモデル (OApply) のビューモデル (OApplyIDViewModel) を使用して、選択したフィールドを更新しようとしています。実行しても変更は反映されません。これを経験した人からの助けに感謝します。エラーは発生しません。フォームが送信され、リダイレクトされます。
私はglobal.asaxでこれを持っています
AutoMapper.Mapper.CreateMap<OApplyIDViewModel, OApply>();
これはビューモデルです
public class OApplyIDViewModel
{
[Key]
public int OAId { get; set; }
[Display(Name = "Identification")]
[Required(ErrorMessage = "Identification Required")]
public int IdId { get; set; }
[Display(Name = "Identification Number")][Required(ErrorMessage="ID Number Required")]
public string AIdentificationNo { get; set; }
[Display(Name = "Licence Version(5b)")]
[RequiredIf("IdId", Comparison.IsEqualTo, 1, ErrorMessage = "Version(5b) Required")]
public string ALicenceVersion { get; set; }
public int CountryId { get; set; }
[RequiredIf("IdId",Comparison.IsNotEqualTo,1, ErrorMessage="Country Required")]
[Display(Name = "Your Electronic Signature Date Seal")]
[Required(ErrorMessage="Date Signature Seal Required")]
public DateTime SigDate { get; set; }
[ScaffoldColumn(false)]
[Display(Name = "Last Updated on")]
public DateTime UDate { get; set; }
[ScaffoldColumn(false)]
[Display(Name = "Last Updated by")]
public String UDateBy { get; set; }
}
これはコントローラーにあります
//得る
public ActionResult ClientEditID(int id)
{
var model = new OApplyIDViewModel();
OApply oapply = db.OApply.Find(id);
if (model == null )
{
return HttpNotFound();
}
ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", model.CountryId);
ViewBag.IdId = new SelectList(db.PhotoIds, "IdId", "IdName", model.IdId);
return View();
}
[HttpPost]
public ActionResult ClientEditId(OApplyIDViewModel oapply, int Id)
{
if (!ModelState.IsValid)
{
return View(oapply);
}
var onlineid = db.OApply.Where(x => x.OAId == Id).FirstOrDefault();
Mapper.Map<OApplyIDViewModel,OApply>(oapply);
oapply.UDateBy = Membership.GetUser().ProviderUserKey.ToString();
oapply.UDate = DateTime.Now;
db.Entry(onlineid).State= EntityState.Modified;
db.SaveChanges();
ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", oapply.CountryId);
ViewBag.IdId = new SelectList(db.PhotoIds, "IdId", "IdName", oapply.IdId);
return RedirectToAction("HomeAccount");
}
これがビューです
@using (Html.BeginForm("ClientEditId", "OApply", FormMethod.Post, new { enctype = "multipart/form-data", @class = "stdform" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>OnlineApplication</legend>
@Html.HiddenFor(model => model.OAId)
<div class="related">
<div class="editor-label">
@Html.LabelFor(model => model.IdId, "IdType")
</div>
<div class="editor-field">
@Html.DropDownList("IdId", String.Empty)
@Html.ValidationMessageFor(model => model.IdId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.AIdentificationNo)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.AIdentificationNo)
@Html.ValidationMessageFor(model => model.AIdentificationNo)
</div>
<div class="requiredfields">
<div class="editor-label">
@Html.LabelFor(model => model.ALicenceVersion)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ALicenceVersion)
@Html.ValidationMessageFor(model => model.ALicenceVersion)
</div>
</div>
<div class="country">
<div class="editor-label">
@Html.LabelFor(model => model.CountryId)
</div>
<div class="editor-field">
@Html.DropDownList("CountryId")
@Html.ValidationMessageFor(model => model.CountryId)
</div>
</div></div>
<div class="editor-label">
@Html.LabelFor(model => model.SigDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SigDate)
@Html.ValidationMessageFor(model => model.SigDate)
</div>
<p>
<input type="submit" value="Save" />
</p>