I am developing an ASP.Net MVC 3 web application using Razor Views. In the view, I would like to ask the user a question that can only have a “Yes / No” answer, so I plan to use two radio buttons.
I have a ViewModel that I pass to my view and it looks like this:
public class ViewModelFormImmigration
{
public int immigrationID { get; set; }
public int formID { get; set; }
[Required(ErrorMessage = "Please select Yes or No.")]
public bool euNational { get; set; }
}
In my view, I have the following lines of code to display the radio buttons for the Yes and No options
@Html.RadioButtonFor(model => model.euNational, true) <text>Yes</text>
@Html.RadioButtonFor(model => model.euNational, false) <text>No</text>
My problem is that when the user first appears in this view, I would not select the Yes or No option. At the moment, when I create an instance of my ViewModel (See above.), Property euNational defaults to false , and when the ViewModel transferred my view, this means that the "No" is automatically selected.
In any case, so that when the user first sees the view that no parameter is selected by default?
Thanks for all your help.
tcode source
share