2012-10-29 60 views

回答

0

在你Home控制器,創建一個處理法名稱Details其具有int參數與名稱id

public class HomeController: Controller 
{ 
    public ActionResult Details(int id) 
    { 
    //get the item from the id and return the view 
    Customer customerModel=repositary.GetCustomerFromId(id); 
    return View(customerModel); 
    } 
} 

假設repositary.GetCustomerFromId方法返回Customer類的一個對象和您的詳細視圖強類型爲Customer類。

@model Customer 
<h2>@Model.FirstName</h2> 
<p>@Model.AddressLine1</p> 

您的默認路由定義,在global.asax中就足夠了。

相關問題