asp.net mvc - Difference between Html Validate and Html ValidateFor -
why use validate , validatefor in validation? using that, not getting error message in ui.
code
<div> @{html.beginform();} @html.textboxfor(x => x.lastname, new { id = "txtlastname" }) @{html.validate("lastname");} @{html.validatefor(x=>x.lastname);} <input type="submit" id="btnsubmit" value="submit" /> @{html.endform();} </div>
this behavior intentional. both these helpers register corresponding parameters client-side validation, without showing message should validation fail. message can still displayed in validationsummary
.
if want show message specific field/parameter, should use validationmessage
or validationmessagefor
instead:
@html.validationmessage("lastname") @html.validationmessagefor(x=>x.lastname)
Comments
Post a Comment