@Html.ActionLink("Edit", "EditArticle", new { ArticleID = article.ArticleID })
我通过 ArticleID 检索文章并返回到编辑页面,如下所示:
public ActionResult EditArticle(Guid ArticleID)
{
AddArticleModel AddArticleModel = new AddArticleModel();
AddArticleModel.Categories = entity.TBL_CATEGORIES.Select(a => a);
AddArticleModel.Article = dbo.SelectArticleById(ArticleID);
return View(AddArticleModel);
}
到这里为止没有问题。
在我的编辑页面中,我正在更改文章的一些属性(不是所有属性)。例如,我正在更改标题、内容和更新日期。像这样:
@model DunyaYazilim.Models.AddArticleModel
@{
ViewBag.Title = "EditArticle";
Layout = "~/Views/Shared/_LayoutAuthor.cshtml";
}
@using (Html.BeginForm((string)ViewBag.FormAction, "Author"))
{
@Html.ValidationSummary(true, "Makale gönderilirken bir hata oluştu. Lütfen daha sonra tekrar deneyin.")
<div>
<div class="label_header">@Html.Label("Kategori Seçiniz:")</div>
<div>@Html.DropDownList("CategoryID", new SelectList(Model.Categories, "CategoryID", "Name"),Model.Article.TBL_CATEGORIES.Name)</div>
<div class="label_header">@Html.Label("Makale Başlık:")</div>
<div>@Html.TextBoxFor(m => m.Article.Title, new { @class = "my_textbox" })</div>
<div class="label_header">@Html.Label("Makale Açıklama:")</div>
<div>@Html.TextAreaFor(m => m.Article.Description, new { @class = "my_textarea" })</div>
<div class="label_header">@Html.Label("Makale İçerik:")</div>
<div>@Html.TextAreaFor(m => m.Article.ArticleContent, new { @class = "my_textarea" })</div>
<div><input type="submit" value="Gönder" class="my_button" /></div>
</div>
}
然后我将其发布到:
[HttpPost]
public ActionResult EditArticle(AddArticleModel AddArticleModel, String CategoryID)
{
//TODO: update database...
return View(AddArticleModel);
}
但未更改的属性返回 null(ArticleID、UserID 等)。所以我无法更新数据库,因为发布后我没有 ArticleID。这是什么原因?
谢谢。