在我的控制器中我確實有這個端點:asp.net MVC參數沒有通過
async Task<FileResult> DownloadSelection(AssignedDatabaseSelection selection)
我的HTML看起來像:
@if (Model.AssignedDatabaseSelections.Any())
{
<table>
@foreach (var selection in Model.AssignedDatabaseSelections)
{
<tr>
<td>@selection.DisplayName</td>
<td width="10%">
@Html.ActionLink(Strings.CsvLabel, "DownloadSelection", "Home", selection, null)
</td>
</tr>
}
</table>
}
現在,我想另一個參數添加到我的控制器方法:
async Task<FileResult> DownloadSelection(AssignedDatabaseSelection selection, DownloadFormat format)
而且
@if (Model.AssignedDatabaseSelections.Any())
{
<table>
@foreach (var selection in Model.AssignedDatabaseSelections)
{
<tr>
<td>@selection.DisplayName</td>
<td width="10%">
@Html.ActionLink(Strings.CsvLabel, "DownloadSelection", "Home", new {selection = selection, Format = DownloadFormat.CSV}, null)
</td>
<td width="10%">
@Html.ActionLink(Strings.ExcelLabel, "DownloadSelection", "Home", new { selection = selection, Format = DownloadFormat.CSV }, null)
</td>
</tr>
}
</table>
}
當我做了檢查內容,我得到這個:現在
<a href="/Home/DownloadSelection?selection=System.Data.Entity.DynamicProxies.AssignedDatabaseSele_D02B1D7B1220921CC4150FAA016EB8BFD5692B52C49949B0ECB80AA2F98E7355&Format=CSV">Excel</a>
,格式被填滿,但是選擇總是空。我錯過了什麼?
如果您不添加'format'參數,您的選擇是否正常工作? – CodingYoshi
mh,而不是當我通過一個新的對象,如新{選擇=選擇} – NPadrutt
所以它沒有任何關係的第二個參數。你如何分配一個「選擇」? – CodingYoshi