2015-03-31 50 views
-1

我怎樣才能獲得數據這是圖像的左下方從視圖控制器當我提交按鈕?MVC4從視圖中獲得表中的數據控制器

鏈接image

public ActionResult EnterInformation1() 
 
     { 
 
      // the ??? is the data from the view; 
 
      TempData['abc'] = ??? 
 
     
 
      return RedirectToAction("Paper"); 
 
     }

我沒有擡頭參考我ask.thanks

+0

包含在問題的代碼不是鏈接。你的問題是什麼? – 2015-03-31 01:16:45

+0

_「包含問題中的代碼而不是鏈接」_你不明白嗎? – 2015-03-31 01:36:50

+0

我想包含代碼,但我沒有足夠的信譽來做到這一點 – 2015-03-31 02:04:04

回答

1

之前,如果你想從視圖中的數據發送到控制器的所有你需要的是做下一步: 1)從控制器發送數據到視圖。比如你要顯示的模型至極的內容列表

public ActionResult ShowList() 
{ 
    List<string> lst = new List<string>() {"1", "2", "3", ,"4"}; 
    return View("MyListView", lst); 
} 

2)使用HTML傭工後綴顯示屏上查看此數據「爲」(例如,textBoxFor,hiddenFor,EditorFor,DisplayFor .. 。)並將其表單標籤

@model List<string> 

    <form action="GetDataFromView" method="post"> 
    <table> 
     <tr> 
     <th>some header</th> 
     <tr> 
     @foreach (var item in Model) { 
     <tr> 
      <td> 
       @Html.DisplayFor(m=> item) 
      </td> 
     </tr> 
     } 
    </table> 
    </form> 

3)控制器至極Write方法裏面會得到這些數據

public ActionResult GetDataFromView(List<string> model) 
{ 
    //do what you want with data sended from view to controller 
    // which stored in parameter model 
    return View("someView"); 
} 
+0

如果我不需要顯示內容一個模型 。我將如何獲取數據。 – 2015-03-31 04:06:10

+0

在這種情況下,您應該使用HiddenFor()而不是DisplayFor() – Tequila 2015-03-31 04:31:52

相關問題