用于打开视图的Asp.net控制器逻辑

时间:2012-12-08 23:11:41

标签: c# post razor view

我正在使用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以Post字段中的post popultated inn的id打开?

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

这是Post字段

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

1 个答案:

答案 0 :(得分:0)

难道你不能这样做吗?

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

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

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

并使用它来更新ActionLink href属性。

相关问题