我有编辑操作方法对:
[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>
}
我做错了什么?
答案 0 :(得分:1)
textarea
中没有内容,因为您没有在标记中指定任何内容:
<textarea class="markitupEditor" cols="15" rows="10" name="ProblemContext">
</textarea>
要么明确地放置内容:
<textarea class="markitupEditor" cols="15" rows="10" name="ProblemContext">
@Html.Raw(Model.ProblemContext)
</textarea>
或者使用构建的TextAreaFor帮助器:
<div class="editor-field">
@Html.TextAreaFor(model => model.ProblemContext,
columns: 15, rows: 10, htmlAttributes: new { @class = "markitupEditor" } )
</div>