我一直在使用Action來獲取報表數據,作爲JSON對象,沒有任何問題使用jQuery的ajax向其發佈表單。動作適用於POST,但不適用於GET(查詢字符串)
但現在我需要根據參數的值返回不同的結果類型。它應該返回JSON,Excel文件(用HTML構建)或PDF文件。所以我在我的控制器類上創建了一個嵌套枚舉來定義可用的返回類型。
但是現在,當我嘗試調用從URL操作產生的文件,它拋出與消息的ArgumentException
:
The parameters dictionary contains a null entry for parameter 'dataInicio' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.ActionResult DadosRelatorioResumoLancamentos(System.Nullable`1[System.Int32], System.String, System.DateTime, System.DateTime, TipoResultado)' in 'Imovelweb.Web.Intranet.Controllers.RelatoriosController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
儘管如此,dataInicio
參數出現在查詢字符串:
我已經嘗試了原始請求(至極返回JSON內容)這兩種方法,並將其與POST的作品名稱,但n與GET一起(拋出相同的ArgumentException
)。
我錯過了什麼?
下面是操作方法的簽名:
public ActionResult DadosRelatorioResumoLancamentos(
int? codFantasia,
string numAp,
DateTime dataInicio,
DateTime dataFim,
TipoResultado tipoResultado = TipoResultado.Json
);
這裏是枚舉:
public enum TipoResultado
{
Json,
Excel,
Pdf
}
如何路由表的樣子嗎?在我看來,MVC正在調用不正確的操作方法 - 沒有dataInicio參數的方法? – 2012-03-21 20:25:28
@TomasVoracek正確的行動正在被調用。問題在於日期格式,正如pjumble的回答中所述。 – Raphael 2012-03-22 14:04:46