Asp.net mvc 4 ASP.NET MVC ViewModel在回发时为空-有时为空
根据我在HTML表单中的输入(6或6.5-或一般情况下,整数与浮点),我会得到或不会得到以下异常(它与int一起工作,与浮点不一起工作): 传递到字典中的模型项为null,但此字典需要类型为“System.Boolean”的非null模型项 我的视图的ViewModel是null,问题在一个自定义模板中可见,该模板需要bool值,但得到的却是null。我们将ASP.NETMVC4与.NET4.0、C#和Razor模板一起使用 经过几个小时的调试,我得出以下结论:Asp.net mvc 4 ASP.NET MVC ViewModel在回发时为空-有时为空,asp.net-mvc-4,razor,.net-4.0,postback,asp.net-mvc-viewmodel,Asp.net Mvc 4,Razor,.net 4.0,Postback,Asp.net Mvc Viewmodel,根据我在HTML表单中的输入(6或6.5-或一般情况下,整数与浮点),我会得到或不会得到以下异常(它与int一起工作,与浮点不一起工作): 传递到字典中的模型项为null,但此字典需要类型为“System.Boolean”的非null模型项 我的视图的ViewModel是null,问题在一个自定义模板中可见,该模板需要bool值,但得到的却是null。我们将ASP.NETMVC4与.NET4.0、C#和Razor模板一起使用 经过几个小时的调试,我得出以下结论: Post表单数据相同(除了一个
- Post表单数据相同(除了一个属性不同,但看起来仍然正确)
- 执行顺序有点奇怪:
- 对于int我得到应用程序\u BeginRequest->Filter,它通过我的属性->操作->查看渲染或重定向(一切正常)
- 对于float我得到应用程序\u BeginRequest->Filter,它通过我的属性->视图渲染->以异常和空视图模型结束
public class JabCommonViewModel
{
public int JAB_ID { get; set; }
[UIHint("Checkbox")]
public bool JAB_gesperrt { get; set; }
[UIHint("Checkbox")]
public bool JAB_Kontrolliert { get; set; }
public int e001 { get; set; }
public string e002 { get; set; }
public int e005 { get; set; }
[UIHint("Checkbox")]
public bool e013 { get; set; }
public bool e014 { get; set; }
public short? e015 { get; set; }
public bool? e149 { get; set; }
public int? e649 { get; set; }
public int? e310 { get; set; }
public int? LastJabe311 { get; set; }
public int jabIdE013 { get; set; }
public int jabIdPrev { get; set; }
public int updCnt { get; set; }
public int checks { get; set; }
public bool calculateInEur { get; set; }
public FormViewModel AktivaPassiva { get; set; }
public FormViewModel GuV1GuV2 { get; set; }
public FormViewModel GuV3 { get; set; }
public ActsFormViewModel ActsForm { get; set; }
public CommonDataViewModel CommonDataForm { get; set; }
public CompanyHeadViewModel CompanyHeadForm { get; set; }
public FacilitiesOverviewModel FacilitiesOverview { get; set; }
}
public class FormViewModel
{
public string ShowAllCaption { get; set; }
public string HideAllCaption { get; set; }
public string CurrentCaption { get; set; }
public string PreviousCaption { get; set; }
public bool HasPreviousData { get; set; }
public IEnumerable<FieldViewModel> Fields { get; set; }
public FormViewModel()
{
Fields = new FieldViewModel[0];
}
}
public class FieldViewModel
{
public string Name { get; set; }
public string Title { get; set; }
public object Value { get; set; }
public bool IsDisabled { get; set; }
public bool IsCollapsible { get; set; }
public bool IsSpecialCase { get; set; } // used currently to expand/collapse groups on second level
public FieldViewModel Previous { get; set; }
public Category DataCategory { get; set; }
public IEnumerable<FieldViewModel> Related { get; set; }
public FieldViewModel()
{
Related = new FieldViewModel[0];
}
public FieldViewModel(string name, string title, object value, bool isDisabled, Category dataCategory = Category.None, bool isCollapsible = true)
{
Name = name;
Title = title;
Value = value;
IsDisabled = isDisabled;
DataCategory = dataCategory;
IsCollapsible = isCollapsible;
Related = new FieldViewModel[0];
}
}
....
发回的帖子实际上是链接
/戳/编辑/
当e751(特殊属性)具有整数值时,仍然会执行正确的方法get。
我们在这个领域也使用了。此外,我们还将插件与其他字段一起使用,但到目前为止,我们仅在这个字段中发现了错误。此外,我们有一个工作站,无法再现错误,因此错误发生在三个工作站中的两个+测试服务器上
到目前为止,我所发现的任何东西都不能解释它有时有效的事实
非常感谢您抽出时间阅读我的帖子
你知道什么地方可能出错,或者我可以检查什么吗?我正在试图找出一个类似的问题,但运气不好。我的视图模型有时是空的,但我不知道为什么?我没有开发该视图,只是应该找到错误并修复它,我没有管理它,但它现在可以工作了。-AFAIK这个家伙更新了jqueryui插件和jQuery验证,它开始工作了。我们还遇到了使用不同类来创建视图并随后对其进行解析的问题(视图是使用Model1创建的,但操作作为参数Model2获得的-非常相似,但不相同)-更改后,为了始终使用相同的模型,最后的错误也消失了(目前)-希望你能找到对你有帮助的东西
public ActionResult Edit(JAB2 jab)
{
ComponentFactory.Logger.Debug("Edit with JAB2");
....
}
public class JAB2 : JAB
{
public int jabIdE013 { get; set; }
public JAB LastJab { get; set; }
public int checks { get; set; }
}
public class JAB : BaseModel
{
public JAB()
{
}
public bool e116 { get; set; }
public bool e117 { get; set; }
public bool e118 { get; set; }
public bool e119 { get; set; }
public bool e120 { get; set; }
public bool e121 { get; set; }
public bool e122 { get; set; }
public bool e123 { get; set; }
public bool e124 { get; set; }
public bool e125 { get; set; }
public short? e126 { get; set; }
... /* 100 more properties */ ...
[LocalizedDisplayName("e751", NameResourceType = typeof(Resources.ModelPropertyNames))]
public float? e751 { get; set; } /* the property which works as int but not as float */
}