無效項我堅持一個奇怪的行爲..我有它返回Excel文件的操作:再次..參數字典包含參數
public ActionResult AgentPortfolioReport(DateTime fromDate, DateTime toDate)
{
...
return File(ms.ToArray(), "application/vnd.ms-excel", "SomeReport.xlsx");
}
然後我把我的觀點:
@Html.ActionLink("Get Report", "AgentPortfolioReport", new { fromDate = DateTime.Today.AddDays(-15), toDate = DateTime.Today }, new { @class = "iin-submit", id = "loadPortfolio" })
一切正常,文件被下載。然後可變日期開始發揮作用。我嘗試使用一個乾淨的JavaScript與功能:
function LoadReport(action, fromDate, toDate) {
window.location = '/Reports/' + action + '?fromDate=' + encodeURIComponent(fromDate) + '&toDate=' + encodeURIComponent(toDate);
}
和繁榮!我得到一個異常:
The parameters dictionary contains a null entry for parameter 'toDate' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult AgentPortfolioReport(System.DateTime, System.DateTime)' in 'AgentsNetwork.Controllers.ReportsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
我也試過用這樣的形式來解決它:
@using (Html.BeginForm("AgentPortfolioReport", "Reports", FormMethod.Get))
{
<div>
Укажите период:<br/>
<label for="fromDate">C </label>
<input id="fromDate" name="fromDate" type="text" />
<label for="toDate"> по </label>
<input id="toDate" name="toDate" type="text" />
</div>
<p>
<input type="submit" value="Get report" />
</p>
}
但結果是一樣的。添加可空的id參數沒有幫助。請給我一個提示有什麼問題..
當不例外發生?表單發佈後?另外,您是否使用任何自定義模型粘合劑? – newmanth
@newmanth請求甚至不會執行任何操作。所以當我點擊一個按鈕時,我得到了這個錯誤。沒有自定義模型聯編程序是用戶。奇怪的是,與Acitonlink一切正常.. – IDeveloper
所以,我認爲你的問題可能是全球化的設置。你的日期條目是什麼格式?例如,您是使用「30.4.2016」還是「30/4/2016」或其他? – newmanth