Difference between 'Html.Validate' and 'Html.ValidateFor'
asp.net-mvc, asp.net-mvc-3, asp.net-mvc-4
Solution
This behavior is intentional. Both these helpers just register corresponding parameters for client-side validation, without actually showing any message should the validation fail. However this message can still be displayed in a `ValidationSummary`.
If you want to show the message specific to the field/parameter, you should use `ValidationMessage` or `ValidationMessageFor` instead:
@Html.ValidationMessage("LastName")
@Html.ValidationMessageFor(x=>x.LastName)
Problem
Why do we use `.Validate` and `.Validatefor` in validation? I am using that, but I am not getting any error message in the 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> ```