UPDATE 好吧,我有一點,我在錯誤的方向=移動),所以,這個想法:如何進入Action並根據MVC中的按鈕點擊傳遞參數?
我有一個表,我的網頁上(View = Index.cshtml
):
<tbody id="SessionListBody">
<tr style="display: none;"> … </tr>
<tr>
<td id="2" class="date"> … </td>
<td> … </td>
<td>
<a class="btn btn-primary btn-sm" href="/Home/MattersSession/2"> … </a>
</td>
</tr>
<tr>
<td id="3" class="date"> … </td>
<td> … </td>
<td>
<a class="btn btn-primary btn-sm" href="/Home/MattersSession/3"> … </a>
</td>
</tr>
<tr>
<td id="4" class="date"> … </td>
<td> … </td>
<td>
<a class="btn btn-primary btn-sm" href="/Home/MattersSession/4"> … </a>
</td>
</tr>
<tr>
<td id="5" class="date"> … </td>
<td> … </td>
<td>
<a class="btn btn-primary btn-sm" href="/Home/MattersSession/5"> … </a>
</td>
</tr>
<tr>
<td id="6" class="date"> … </td>
<td> … </td>
<td>
<a class="btn btn-primary btn-sm" href="/Home/MattersSession/6"> … </a>
</td>
</tr>
每一行都包含按鈕。我需要得到該行的第一td
的id
被點擊按鈕時,並通過這個id
到我的行動:
public ActionResult MattersSession(int sessionPageID)
{
DBAccess dba = new DBAccess();
DataTable dt = dba.GetSessionPage(sessionPageID);
Session["SourceFileID"] = dt.Rows[0]["SourceFileID"];
Session["SessionPageID"] = sessionPageID;
// Generate Table and pass it to the View
ViewData["MattersTable"] = dt.Rows[0]["MainTableBody"];
ViewData["SummaryTable"] = dt.Rows[0]["SummaryBody"];
return View("Matters");
}
現在,當我點擊我得到這個錯誤鏈接:
The parameters dictionary contains a null entry for parameter 'sessionPageID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult MattersSession(Int32)' in 'QuickbookUploadFromElite3e.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
但我需要這個參數來調用這個方法DataTable dt = dba.GetSessionPage(sessionPageID);
,所以如果我會做這個參數可選,這將是comile錯誤?
嘗試添加一個參數給你的錯誤函數'error:function(e){'並提醒'e.message'? – brandonscript
是你的控制器被擊中的方法,並被填充的ID? –
您需要將'dataType:json'更改爲'dataType:html' – PSL