asp.net mvc - UpdateModel change MVC1 vs MVC3 -
i'm converting app asp.net mvc 1 mvc 3, ran problems when calling updatemodel()
when submitting form.
here model class:
public class testmodel { public string name { get; set; } public string description { get; set; } public int age { get; set; } public int? subvalue { get; set; } public int agesub { { return subvalue.value - age; } } }
and in controller:
[acceptverbs(httpverbs.post)] public actionresult testmodelsave() { testmodel tm = new testmodel(); try { updatemodel(tm); if (modelstate.isvalid) { return redirecttoaction("testmodeledit"); } } catch { } return view("testmodeledit", tm); }
if leave subvalue null when submit, in mvc 1 works fine. in mvc 3, when call updatemodel(tm)
throws exception on line return subvalue.value - age;
in testmodel class.
i go , change subvalue.value
subvalue.getvalueordefault()
, don't want have that. why change made between versions of mvc?
if code worked under mvc1 (and can't understand how would), pure luck. should throw exception if try access value of nullable int that.
your code broken, , should fix it. don't complain used work, because if did, shouldn't have.
Comments
Post a Comment