2011-12-22 62 views
0

新來的MVC MVC應用程序流,在一個MVC應用程序在用戶不根據日期和地點的主頁上尋找工作,然後服務返回,我填的泛型列表,則所需的產品記錄我在另一個視圖上顯示這些記錄,現在我想要做的是用戶能夠選擇一個產品並執行產品請求。一些產品的數據

public ActionResult Index() 
      {    
       DateTime dt = System.DateTime.Now.AddDays(7); 
       var m = (from i in Enumerable.Range(0, 12) 
         let now = DateTime.Now.AddMonths(i) 
         select now.Month + " " + now.ToString("MMMM") + " " + now.Year.ToString()).ToList();      

       ViewBag.day = dt.Day; 
       ViewBag.b = m; 

       return View();         
     } 


[HttpPost] 
public ActionResult Index(DateTime PickUpDate, string location) 
      { 
     //fill data from service 
    TempData["CollectionTemp"] = CollectionList; 

       return RedirectToAction("Result"); 
    } 

public ActionResult Result() 
     { 
      List<myCollection> CollectionResult = new List<myCollection>(); 
      CollectionResult = TempData["CollectionTemp"] as List<myCollection>; 

      return View(CollectionResult); 
     } 

public class myCollection 
     { 
      public Datetime date { get; set; } 
      public string location { get; set; } 
} 

在結果視圖我使用剃刀

@if (Model != null) 
{ 
    foreach (var prd in Model) 
    { 
    fill the table with data 
    } 
} 

現在我想要做的是創建一個鏈接重定向到一個新的視圖中的每個產品中顯示記錄的所有細節都顯示對於那個特定的產品。怎麼樣 ?鏈接是歡迎

回答

2

這是一個相當普遍的事情要做 - 有一堆教程那裏 - 這一個是相當全面的:http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part1-cs(第5部分是它進入這個特定位:http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/getting-started-with-mvc3-part5-cs)。

本質上,你可以做的是創建一個actionlink,將你正在編輯的項目的ID傳遞給控制器​​上的一個action方法,然後獲取該項目的所有細節並返回一個視圖進行編輯。

1

當你顯示記錄,創建像
的foreach()
{ @ html.Actionlink鏈路爲每個產品( '一個', 'actionName', '控制器',新{ID =放慢參數}) }
當此渲染頁面,這將顯示所有產品信息的超鏈接。

請讓我知道如果您需要任何幫助