I have a series of radio buttons, one must be selected whent he 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 ensure that the form doesn't submit and the @Html.ValidationSummary() is populated with a "OrderAction must be selected" string?
To validate RadioButtonList in JavaScript <asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem Value="Java">Java</asp:ListItem> <asp:ListItem Value="Dot Net">Dot Net</asp:ListItem> <asp:ListItem Value="JavaScript">JavaScript</asp:ListItem>
ASP.NET Web Forms RadioButton. It is an input control which is used to takes input from the user. It allows user to select a choice from the group of choices. To create RadioButton we can drag it from the toolbox of visual studio. This is a server side control and ASP.NET provides own tag to create it.
ASP.NET MVC client side validation is based on the jQuery validation plugin. It can be said that MVC's client-side validation is an opinionated version of how jQuery validation should work in an ASP.NET MVC project. Despite this, the underlying implementation is fully based on jQuery's.
We do not need to write any specific code to check the radio button. They can be checked once they are created or specified in HTML form.
Just tag the OrderAction
property in your model with this:
[Required(ErrorMessage = "OrderAction must be selected")]
I assume you have client validation enabled in either the web.config or the view and you have included the jquery validation file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With