I want to pass model from form to controler and show others models in the same view. How can I do this? My main problem is: how to send into testAcc actionresult, model CommentModel, and show text in ViewData["Success"]
?
Here is my code:
@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"]
wrapper:
public class _ideaDetailsWrapper
{
public Ideas idea { get; set; }
public IEnumerable<IdeasComment> commentList { get; set; }
public CommentModel addComment { get; set; }
}
Action method:
[HttpPost]
[Authorize]
public ActionResult testAcc(CommentModel model)
{
CommentModel abs = model;
ViewData["Success"] = "Working!";
// ADD TO DATABASE, but model is null..
return RedirectToAction("Details", "Ideas");
}
See Question&Answers more detail:os