1

我有编辑操作方法对:

[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>
}

我做错了什么?

4

1 回答 1

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>
于 2012-08-16T08:24:47.533 回答