Rap*_*ael 2 c# asp.net-mvc asp.net-mvc-2
我一直在使用Action获取报告的数据,作为JSON对象,使用jQuery的ajax将表单发布到它上面没有问题.
但是现在我需要根据参数的值返回不同的结果类型.它应该返回JSON,Excel文件(使用HTML构建)或PDF文件.所以我在我的控制器类上创建了一个嵌套枚举,用于分隔可用的返回类型.
但是现在,当我尝试从URL调用Action来生成文件时,它会抛出一条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,但不适用于GET(ArgumentException抛出相同的内容).
我错过了什么?
这是Action方法的签名:
public ActionResult DadosRelatorioResumoLancamentos(
int? codFantasia,
string numAp,
DateTime dataInicio,
DateTime dataFim,
TipoResultado tipoResultado = TipoResultado.Json
);
Run Code Online (Sandbox Code Playgroud)
以下是枚举:
public enum TipoResultado
{
Json,
Excel,
Pdf
}
Run Code Online (Sandbox Code Playgroud)
我有这个问题,默认的ASP.NET MVC模型绑定器将QueryString值解析为InvariantCulture,而POSTed表单值将使用解析CurrentCulture.
这意味着在您的GET请求中,它将尝试以美国格式MM/dd/yyyy解析21/03/2012,这是无效的.由于您的dataInicio参数不可为空,因此无法提供合适的值,因此它会抛出一个ArgumentException.
这里有一个完整的注释/解决方法:http://weblogs.asp.net/melvynharbour/archive/2008/11/21/mvc-modelbinder-and-localization.aspx
| 归档时间: |
|
| 查看次数: |
1207 次 |
| 最近记录: |