Reputation: 15
I making a MVC2 project
View:
<%= Html.DropDownListFor ( m => m.CategoryId, Model.CategoryList )%>
<%= Html.ValidationMessageFor ( m => m.CategoryId )%>
<br />
<%if ((Html.TextBoxFor(m => m.NewCategory)).Equals("")) %>
<%{ show error msg near the textbox "* field is required"}%>
<% else %>
<%= Html.TextBoxFor(m => m.NewCategory)%>
If textbox is empty then show error msg and let the user to input again, how to do this?? :S
Upvotes: 0
Views: 114
Reputation: 9285
put a " [Required]" condition to the Property of your Model.
public class MyModel {
[Required]
public string NewCategory { get; set; }
}
A complete explained example can be found there: http://www.codeproject.com/Articles/220025/A-sample-on-Asp-Net-MVC-Model-Validation-using-Dat
Upvotes: 1