QED*_*QED 13 c# asp.net-mvc defaultmodelbinder model-binding asp.net-mvc-2
我有一个控制器动作,其定义如下 -
public ActionResult ChangeModel( IEnumerable<MyModel> info, long? destinationId)
Run Code Online (Sandbox Code Playgroud)
而型号:
public class MyModel
{
public string Name; //Gets populated by default binder
public long? SourceId; //remains null though the value is set when invoked
}
Run Code Online (Sandbox Code Playgroud)
在"名称"属性,都会在控制器动作人口不过的sourceID财产保持为空.该目标-ID这是一个很长?参数也会被填充.
在单步执行MVC(版本2)源代码时,这是DefaultModelBinder抛出的异常.
从类型'System.Int32'到类型'System.Nullable`1 [[System.Int64,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]]的参数转换失败,因为没有类型转换器可以转换这些类型.
如果模型更改为long而不是long?,则默认模型绑定器会设置该值.
public class MyModel
{
public string Name {get;set;}; //Gets populated by default binder
public long SourceId {get;set;}; //No longer long?, so value gets set
}
Run Code Online (Sandbox Code Playgroud)
这是一个已知的问题?由于MVC源代码已经过优化,我无法单步执行大部分代码.
更新:正在发送的请求是使用Json与源JSon类似的Http POST -
{"info":[{"Name":"CL1","SourceId":2}], "destinationId":"1"}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3066 次 |
| 最近记录: |