見下文:有人可以解釋這個Linq-To-Sql代碼有什麼問題嗎?
Edit.aspx查看:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Test.Models.Friend>" %>
編輯
<h2>Edit</h2>
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.Id) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Id) %>
<%= Html.ValidationMessageFor(model => model.Id) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Name) %>
<%= Html.ValidationMessageFor(model => model.Name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Link) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Link) %>
<%= Html.ValidationMessageFor(model => model.Link) %>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
<div>
<%= Html.ActionLink("Back to List", "Index") %>
</div>
控制器編輯:
[Authorize(Roles = "Administrator")]
public ActionResult Edit(int id)
{
var eddy = friendsDB.Friends.Single(a => a.Id == id);
return View(eddy);
}
[HttpPost]
public ActionResult Edit(int id, string confirmButton)
{
var eddx = friendsDB.Friends.Single(a => a.Id == id);
try
{
UpdateModel(eddx, "Friend");
friendsDB.SubmitChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
不更新,所以它不是一個令人耳目一新的看法。 它通過議案,並返回到應該發生的「索引」,但該記錄保持未經編輯。任何想法或替代編輯與LINQ到SQL?謝謝。
澄清是顯示未更新還是數據庫中的實際記錄未更新? – Ahmad 2010-07-30 06:06:02