I have an error validation issue with an int.
I have validation for a customer name:
if (String.IsNullOrEmpty(CustomerName))
yield return new RuleViolation("Customer Name Required", "CustomerName");
now if I want to add validation for a city, in this case I have a CityID that gets saved as type int, so I can't write my if statement the same way...because there's no int.IsNullOrEmpty method. Let's say the user didn't select the dropdown for city - it's basically saving with no value.
What's the best way to write my validation statement for an int?
UPDATE:Here's a sample of what I have for my form in my view:
<% using (Html.BeginForm())
{%>
<fieldset>
<legend>Add a new customer</legend>
<p>
<label for="CustomerName">Customer Name:</label>
<%= Html.TextBox("CustomerName")%>
<%= Html.ValidationMessage("CustomerName", "*")%>
<label for="CityID">City:</label>
<%= Html.DropDownList("CityID", Model.Cities as SelectList, "Select City")%>
<%= Html.ValidationMessage("CityID", "*")%>
<input type="submit" value="Create New Customer" />
</p>
</fieldset>
<% } %>
and my view model looks like this:
public class CustomerFormViewModel
{
//Properties
public Customer Customer { get; set; }
public SelectList Cities { get; set; }
//Constructor
public CustomerFormViewModel(Customer customer)
{
CustomerRepository customerRepository = new CustomerRepository();
Customer = customer;
Cities = new SelectList(customerRepository.FindAllCities(), "CityID", "CityName");
}
}