asp.net mvc 4 - Range Validation is not working -


i have used range validation not working. adding model,controller , view code.please help(i have added related fields in code).

model :

public class ticketdetailmodel : ticketmodelbase     {         public workonticketcreatemodel workonticketcreatemodel { get; set; }     } public class ticketmodelbase     {         [required]         [range(1, int.maxvalue, errormessage = "please enter value bigger {0}")]         public int estimatedtime { get; set; }         public virtual list<workonticket> workontickets { get; set; }     } public class workonticketcreatemodel : workonticketmodelbase     {         [required]         [display(name = "assignedtouser")]         public int assignedtouserid { get; set; }         public ienumerable<selectlistitem> assigneduser { get; set; }          [required]         [display(name = "ticket status")]         public int ticketstatusid { get; set; }          public ticketstatus ticketstatusval { get; set; }          public ienumerable<selectlistitem> ticketstatus { get; set; }      }  public class workonticketmodelbase     {         public int id { get; set; }          [required]         public int estimatehours { get; set; }          [required]         [range(1, int.maxvalue, errormessage = "please enter value bigger {0}")]         public int workedhours { get; set; }      } contoller:         [httppost]         [acceptverbs(httpverbs.post)]         public actionresult details(ticketdetailmodel model, ienumerable<httppostedfilebase> file)         {             using (itransaction transaction = this.nhsession.begintransaction())             {                  var ticketobj = this.nhsession.queryover<ticket>().where(t => t.id == model.id).singleordefault();                 var workonticket = new workonticket();               workonticket.ticket = ticketobj;                     workonticket.workedhours = model.workonticketcreatemodel.workedhours;                     workonticket.estimatehours = model.workonticketcreatemodel.estimatehours;                                ticketobj.workontickets.add(workonticket);                 this.nhsession.save(ticketobj);                 transaction.commit();             }             return redirecttoaction("details", new { id = model.id, milestoneid = model.milestone.id, projectid = model.project.id });         } 

view:-

@model anktech.ticketmanagement.web.models.ticket.ticketdetailmodel @using (html.beginform("details", "ticket", formmethod.post, new { enctype = "multipart/form-data" })) {    @html.validationsummary(true)  @html.textboxfor(model => model.workonticketcreatemodel.estimatehours, new { @id = "work_remaining", @class = "s-mini", size = "2" }) worked hours:                                                                            @html.textboxfor(model => model.workonticketcreatemodel.workedhours, new { @id = "worked_hours", @class = "s-mini", size = "2" }) <input type="submit" value="submit" tabindex="2" name="commit" id="submit-comment"  class="gray-btn"> } 

i have deleted rmaining fields. have added fields related asking, please help.

you need use modelstate.isvalid check model valid. assign validation attributes never check them:

[httppost] [acceptverbs(httpverbs.post)] public actionresult details(ticketdetailmodel model, ienumerable file) {     if (!modelstate.isvalid)     {         // handle error     }     else     {             using (itransaction transaction = this.nhsession.begintransaction()) {             var ticketobj = this.nhsession.queryover<ticket>().where(t => t.id == model.id).singleordefault();             var workonticket = new workonticket();             workonticket.ticket = ticketobj;             workonticket.workedhours = model.workonticketcreatemodel.workedhours;             workonticket.estimatehours = model.workonticketcreatemodel.estimatehours;                            ticketobj.workontickets.add(workonticket);             this.nhsession.save(ticketobj);             transaction.commit();         }                 }     return redirecttoaction("details", new { id = model.id, milestoneid = model.milestone.id, projectid = model.project.id }); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -