razor - ASP.NET MVC ViewModel is null on Post Back - sometimes -


depending on input in html form (6 or 6.5 - or in general, integer vs float) or don't following exception (it works int , doesn't work float):

the model item passed dictionary null, dictionary requires non-null model item of type 'system.boolean'.

the viewmodel of view null , problem gets visible in custom template expects bool value, gets null instead. use asp.net mvc 4 .net 4.0, c# , razor templates.

after several hours debugging came following conclusion(s):

  • post form-data identical (except 1 property different, still correct)
  • the execution order somehow weirdly different:
    • for int application_beginrequest->filter runs through attributes->action->view rendering or redirect (everything normal)
    • for float application_beginrequest->filter runs through attributes->view rendering->end exception , empty viewmodel

i have checked dozen times -> if pass float view somehow gets rendered without action (which have seen) executed (and of course breakpoints same time). unfortunately couldn't see in stacktrace anymore once view got rendered.

the viewmodel of view is:

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 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];     } }  .... 

the post-back action

public actionresult edit(jab2 jab) {     componentfactory.logger.debug("edit 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; } /* property works int not float */ } 

the post-back link

/jab/edit/

still correct method get's executed when e751 (the special property) has integer value. use autonumeric-javascript plugin on field. use plugin other fields far found error one. well, have 1 workstation aren't able reproduce error occurs on 2 out of 3 workstations + test server.

so far, nothing i've found explains fact works sometimes.

thank taking time , reading post.

do have ideas wrong or check?


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -