ASP.NET MVC 4 Client Side Authentication Required for Radio Buttons

I have a series of switches, I need to choose when the user clicks the submit button:

@Html.RadioButtonFor(o => o.EquityOrder.OrderAction, EnumOrderAction.B, new {id = "actionBuy"}) @Html.RadioButtonFor(o => o.EquityOrder.OrderAction, EnumOrderAction.S, new {id = "actionSell"}) 

Is there a way to guarantee that the form will not be submitted and that the @ Html.ValidationSummary () element is filled with the string "OrderAction must be selected"?

+7
asp.net-mvc razor asp.net-mvc-4
source share
1 answer

Just mark the OrderAction property in your model as follows:

 [Required(ErrorMessage = "OrderAction must be selected")] 

I assume that you have included client validation in the web.config file or in the view, and you have included the jQuery validation file.

+14
source share

All Articles