Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is something wrong here:</p> <pre><code> var onlineid = db.OApply.Where(x =&gt; x.OAId == Id).FirstOrDefault(); -&gt; Mapper.Map&lt;OApplyIDViewModel,OApply&gt;(oapply); oapply.UDateBy = Membership.GetUser().ProviderUserKey.ToString(); oapply.UDate = DateTime.Now; db.Entry(onlineid).State= EntityState.Modified; </code></pre> <p>The line with the arrow returns a new <code>OApply</code> instance. It does not update <code>onlineid</code>. In fact, it has no idea about <code>onlineid</code>. Try the following.</p> <pre><code>Mapper.Map&lt;OApplyIDViewModel,OApply&gt;(oapply, onlineid); </code></pre> <p>Now it will modify <code>onlineid</code> instead of returning one. However, you should ignore the mapping for the primary key if it is an <code>identity</code> (auto-incrementing) one.</p> <pre><code>AutoMapper.Mapper.CreateMap&lt;OApplyIDViewModel, OApply&gt;() .ForMember(dest =&gt; dest.OAId, opt =&gt; opt.Ignore()); </code></pre> <p>I am not sure if <code>OAId</code> is your primary key or not. You are not following naming conventions and probably some other conventions too, at all.</p> <hr> <p>I have made corrections in your code :</p> <pre><code>public ActionResult ClientEditID(int id) { OApply oapply = db.OApply.Find(id); -&gt;if (oapply == null ) { return HttpNotFound(); } -&gt;var model = Mapper.Map&lt;OApply, OApplyIDViewModel&gt;(oapply); ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", model.CountryId); ViewBag.IdId = new SelectList(db.PhotoIds, "IdId", "IdName", model.IdId); -&gt;return View(model); } </code></pre> <p>Your <code>HttpPost</code> is mostly valid, except that you put data into <code>ViewBag</code> before you use <code>RedirectToAction()</code>. That data will be lost. Instead, use <code>TempData</code> dictionary. Check msdn. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload