c# - How to validate int value from SQL Express in MVC 4 -


i have create view:

 <div class="editor-field">  @html.textboxfor(model => model.first, new { @id = "id1"})       @html.validationmessagefor(model =>model.first)         </div> 

and submit button after textbox:

<input type="submit" value="create" /> 

part of model class looks this:

public int? first { get; set; } 

and web.config:

<add key="clientvalidationenabled" value="true" /> <add key="unobtrusivejavascriptenabled" value="true" /> 

so need check if value first in database before post one. if value in database add error.

i understand part modelstate.addmodelerror cant arround this: every time check value null result not database checks if form textbox empty or not.

please help. in advance.

you going need check on server side once values have been posted.

in case can run query check once page has been posted... if validation condition fails add error manually , return same view. client same if error had been picked unobtrusive validation.

i'm not sure how data layer setup wont go specifics on running query, however, here how handle adding validation errors in controller...

modelstate.addmodelerror("first", "number in use - bad user!"); 

you can return view normal , able see error/ correct issue

return view(model); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -