I have a dropdown in asp.net MVC 4 razor view like this:
@{Html.EnableClientValidation(true);}
@using (Html.BeginForm("AddToCart", "Home", FormMethod.Post, new { id = "product-options" }))
{
<select id="items">
<option value="0">Select</option>
@foreach (var option in item.OptionValues)
{
<option @option.ItemOptionValueID>@option.Value</option>
}
</select>
<a href="javascript:$('#product-options').submit();" class="btn btn-orange-2ln">
<span>Continue Shopping</span>
</a>
}
[HttpPost]
public ActionResult AddToCart(int Id, other properties ...)
{
CartItemInfo model = new CartItemInfo();
model.CustomerID =1;
ItemBiz.AddItemToCart(model);
int cartCount = 0;
if (User.Identity.IsAuthenticated)
{
int CustomerId = MembershipBiz.GetCustomerIDByUserID(WebSecurity.CurrentUserId);
cartCount = ItemBiz.GetCartItemsByCustomerID(CustomerId).Count();
}
return view();
}
I want to make it compulsory field so that if "Select" is option, user sees an error message. how to do this ?