If you are using ASP.NET MVC 2 or 3 then you should checkout DataAnnotations
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
http://www.asp.net/mvc/tutorials/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript
They let you specify your validation constraints on your Domain Model and have the UI automatically generate the validation code for you.
In this case you might have a model
public class MyModel
{
[Required]
public string City { get; set; }
}
then your view uses that model
@model MyModel
@Html.TextBoxFor(x => x.City)
@Html.ValidationMessageFor(x => x.City)
Update
For a drop-down, I tend to do the following, not 100% sure it's optimal but it works
public class MyModel
{
[Range(1,int.MaxValue,ErrorMessage="Please select a value")]
public int OtherModelID { get; set; }
public IList<OtherModel> OtherModels {get; set; }
}
then in the view
@model MyModel
<select id="OtherModelID" name="OtherModelID">
<option value="0">Please Select</option>
@foreach(var m in Model.OtherModel)
{
<option value="m.ID">m.Name</option>
}
</select>
You can put a condition in there to select the current value as well if you're on an edit screen.