12

フォームからコントローラーにモデルを渡し、他のモデルを同じビューに表示したいと考えています。これどうやってするの?私の主な問題は、どのように 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");
    }
4

1 に答える 1