我想将模型从表单传递到控制器并在同一视图中显示其他模型。我怎样才能做到这一点?我的主要问题是:如何发送到 testAcc actionresult、模型 CommentModel 和显示文本ViewData["Success"]
?
这是我的代码:
@model XYZ.Models._ideaDetailsWrapper
@using XYZ.Tools
<article>
<h2>@Model.idea.Tilte</h2>
<table><tr><td>
<p>
Author: <b>@UserTools.getUser(Model.idea.AuthorID).UserName</b><br />
Add date: @Model.idea.AddDate<br />
Category: @IdeasTools.getCategoryName(Model.idea.CategoryID)<br />
</p></td>
</tr></table>
<p><b>Content:</b><br />
@Model.idea.Content</p>
<br /><br />
// HERE - ADD comment
@using (Html.BeginForm("testAcc", "Ideas", FormMethod.Post))
{
<h4>Add comment:</h4>
@Html.LabelFor(m => m.addComment.Content)
@Html.EditorFor(m => m.addComment.Content)<br />
<input type="submit" value="SendEmails" />
}
@ViewData["Success"]
包装:
public class _ideaDetailsWrapper
{
public Ideas idea { get; set; }
public IEnumerable<IdeasComment> commentList { get; set; }
public CommentModel addComment { get; set; }
}
动作方法:
[HttpPost]
[Authorize]
public ActionResult testAcc(CommentModel model)
{
CommentModel abs = model;
ViewData["Success"] = "Working!";
// ADD TO DATABASE, but model is null..
return RedirectToAction("Details", "Ideas");
}