我有编辑操作方法对:
[HttpGet]
public ActionResult Edit(Guid id) {
return View(this.session.Load<Article>(id));
}
[HttpPost, ValidateAntiForgeryToken]
public ActionResult Edit(Article article) {
if(ModelState.IsValid) {
article.ProblemContext = BBCode.ToHtml(article.ProblemContext);
article.AuthorId = this.userService.GetActiveDirectoryUserId(User.Identity.Name);
article.CreatedOn = DateTime.Now;
this.session.Store(article);
this.session.SaveChanges();
TempData["Message"] = String.Format("Article '{0}' was saved successfully", article.Title);
return RedirectToAction("Index", "Home", new { area = "" });
}
return View(article);
}
一切都很好,除了在编辑条目时没有在MarkitUp
-ish textarea 中加载任何内容。
Edit
视图如下所示:
@using(Html.BeginForm("Edit", "Article", new { area = "" }, FormMethod.Post, new { enctype = "multipart/form-data" })) {
@Html.ValidationSummary()
@Html.AntiForgeryToken()
<fieldset>
<legend>Create/Edit</legend>
@Html.HiddenFor(model => model.Id)
<div class="editor-label">@Html.LabelFor(model => model.Title)</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
</div>
<hr />
<div class="editor-field">
<textarea class="markitupEditor" cols="15" rows="10" name="ProblemContext"> </textarea>
</div>
<hr />
<input type="submit" value="Save" />
<input type="reset" value="Clear" />
</fieldset>
} @* using(Html.BeginForm("Edit", "Article", new { area = "" }, FormMethod.Post)) { *@
<script type="text/javascript">
$(function() {
$("#content textarea.markitupEditor").markItUp(mySettings);
});
</script>
@section Stylesheets {
<link href="@Url.Content("~/Scripts/MarkitUpEditor/skins/markitup/style.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Scripts/MarkitUpEditor/sets/bbcode/style.css")" rel="stylesheet" type="text/css" />
}
@section Javascript {
<script src="@Url.Content("~/Scripts/MarkitUpEditor/jquery.markitup.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MarkitUpEditor/sets/bbcode/set.js")" type="text/javascript"></script>
}
我做错了什么?