0

我使用 mvc3 和代码优先脚手架,第一个片段来自 /post/index.cshtml

    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
        @Html.ActionLink("Details", "Details", new { id=item.Id }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.Id }) | 
        @Html.ActionLink("Comment", "Comment", new { id=item.Id })
    </td>

我应该在动作中添加什么以使 /Commment/Create.cshtml 打开并使用帖子填充客栈的 ID 打开帖子字段?

    public ActionResult Comment(int id)
    {
        throw new NotImplementedException();
    }

这是帖子字段

    <div class="editor-label">
        @Html.LabelFor(model => model.PostID, "Post")
    </div>
    <div class="editor-field">
        @Html.DropDownList("PostID", String.Empty)
        @Html.ValidationMessageFor(model => model.PostID)
    </div>
4

1 回答 1

0

你就不能这样做吗?

<td>
    @Html.ActionLink("Comment", "Comment", new { id = Model.PostID })
</td>

还是您想从 DropDownMenu 中获取当前值?在这种情况下,您需要使用 Javascrip/jQuery:

var currentPostId = $('#PostID').val();

并使用它来更新 ActionLinkhref属性。

于 2012-12-09T00:47:50.657 回答