2012-12-08 62 views
0
Asp.net控制器逻辑使用MVC3和代码第一scaffoling

IM,这第一个片段是从/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打开与邮政popultated客栈的邮政编号字段的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> 
+1

也许我不太了解你的要求。但是试着看一下RedirectToAction方法或者TempData。 – mipe34

回答

0

你不能仅仅做到这一点?

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

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

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

并用它来更新ActionLink的href财产。