asp.net mvc 4 - MVC4 model binding and int/decimal overflow -


let's created model property int? type.

public class mymodel {     [range(-100, 100, errormessage="too large")]     public int? myvalue { get; set; } } 

in view use text box in form post server.

    @using (html.beginform())     {         <p>enter value</p>         <div>@html.textboxfor(m => m.myvalue)</div>         <div>@html.validationmessagefor(m => m.myvalue)</div>         <input type="submit" value="submit" />     } 

here controller code

public class homecontroller : controller {     public actionresult index()     {         var model = new mymodel();         return view(model);     }      [httppost]     public actionresult index(mymodel model)     {         return view(model);     } } 

now if enter extremely large number in text box, e.g 111111111111111111111111111111111111111111111111111111111111111111111111111111, sure large integer data type. on post back, got message the value '111111111111111111111111111111111111111111111111111111111111111111111111111111' invalid.

but have no way use error message (localization , on) defined in model.

using system.componentmodel.dataannotations;     public class mymodel {     [range(int.minvalue, int.maxvalue)]     public int? myvalue {get; set; } } 

that should trick.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -