ASP.NET.MVC异常--无法将类型为System.Int32的对象强制转换为类型System.String
2016-11-14 18:34
639 查看
异常描述:
断点调试的时候,程序未执行到action,就报错了,检查了View,未发现错误,之后检查model,发现错误,错误是在一个int类型的属性上加了[StringLength]注解.
异常信息:
说明:执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.InvalidCastException: 无法将类型为“System.Int32”的对象强制转换为类型“System.String”。
堆栈跟踪:
[InvalidCastException: 无法将类型为“System.Int32”的对象强制转换为类型“System.String”。]
System.ComponentModel.DataAnnotations.StringLengthAttribute.IsValid(Object value) +46
System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value, ValidationContext validationContext) +115
异常解决:
检查出错的View 对应的model中,是否有int类型的属性,注解了[StringLength],如果有,移除掉即可相关文章推荐
- 关于MVC中无法将类型为“System.Int32”的对象强制转换为类型“System.String”的问题。
- Linq集合查询出现无法将类型为“System.Int32”的对象强制转换为类型“System.String”异常
- 无法将类型为“System.Int32”的对象强制转换为类型“System.String”
- C#.NET开发Winform使用MySQL数据库 无法将“System.Byte[]”的对象强制转换为类型“System.IConvertible”
- 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”
- 个推推送时,Log4net 无法将类型"System.RuntimeType"的对象强制转换为类型"log4net
- 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”分析及解决方案
- 无法将类型为“Oracle.DataAccess.Types.OracleString”的对象强制转换为类型“System.String”。
- C# 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。
- C# 类型“System.String”的对象无法转换为类型“System.Int32”
- 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”。
- c#:无法将类型为“System.DBNull”的对象强制转换为类型“System.String”
- “WebProxyWrapper”的对象强制转换为类型“System.Net.WebProxy
- MVC 无法将类型“System.Collections.Generic.List<AnonymousType#1>”隐式转换为“System.Collections.Generic.IList<Mvc3Modeltest.Models.Movie>”。存在一个显式转换(是否缺少强制转换?))
- c # xml操作 (无法将类型为“System.Xml.XmlComment”的对象强制转换为类型“System.Xml.XmlElement”)
- 无法将类型为“Finisar.SQLite.SQLiteConnection”的对象强制转换为类型“System.Data.Common.DbConnection”。
- 无法将类型为“System.Security.Principal.GenericIdentity”的对象强制转换为类型“System.Web.Security.FormsIdentity”的错误
- 无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.TextBox
- 无法将类型为“IList”的对象强制转换为类型“System.Data.DataRowView” 。的解决方法
- 无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web