I have an update function, for example:
public void Update(HomeBanner homebanner) { homebanner.EnsureValid(); DataSource.DataContext.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, homebanner); DataSource.DataContext.SubmitChanges(); }
And I am writing an update controller
[AcceptVerbs(HttpVerbs.Post)] //[ValidateAntiForgeryToken] [ValidateInput(false)] public ActionResult ManageImages(int ? id,FormCollection form) { HomeBanner homebanner= BannerRepository.RetrieveById(id); this.TryUpdateModel(homebanner); string photoName = saveImage("photo"); if (photoName != string.Empty) homebanner.ImageID = photoName; BannerRepository.Update(homebanner); return RedirectToAction("list", "Admin"); }
and then view:
<% using (Html.BeginForm("ManageImages", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" })) {%> <h3>Manage Images</h3> <div class="label-field"> <label for="ID">Chọn vị trí:</label> <%= Html.DropDownList("ID", DataHelper.Banner().ToList().ToSelectList("value", "name",Model.HomeBanner.ID.ToString()))%> </div> <div class="label-field"> <label for="photo"> Chọn hình</label> <input type="file" name="photo" value=""/> </div> <div class="label-field"> <label for="Link"> Liên kết</label> <input type="text" name="Link"/> </div> <p> <input type="submit" value="Lưu" /> </p> <% } %>
It also receives data, but the update step was unsuccessful: check here
DataSource.DataContext.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, homebanner);
and throw exception: The object specified for the update is not recognized. I don’t know why, I see the data populated by the object when I debug it. Plz someone helping me!
source share