2012-12-08 63 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財產。