REMESQ
REMESQ

Reputation: 1200

Trying to pass checkbox list enum value to my view

Just trying to do some quick and dirty testing. I am passing fake data through my controller to a view just to see how the UI looks.

In my controller which I set up just to "test" this I have, for example:

MyViewModel = new MyViewModel
{
  MyModel= new Models.MyModel
  {
      FirstName = "Homer", //This works
      SomeDecimal = 10000, //This works
      SomeRadioButton = Models.MyModel.Enum.Selection, //This works
      SomeCheckBox = Models.MyModel.OtherEnum.OtherSelection, //This doesn't
  }
}

I am getting the Cannot implicitly convert type ... to 'System.Collections.Generic.List<string>' error.

My radio buttons and check boxes share similar convention for using enums, but the checkbox uses public List<string> SomeCheckBox { get; set; } whereas radio buttons use public Enum? SomeRadioButton { get; set; }

Please note, I am not using a testing framework. I am just trying to figure out quickly how to pass some fake data to see how the UI is shaping up. Can anyone share a sample of how to accomplish what I want (to pass a checkbox value so my UI can show data that would have been selected by a user)?

The other problem I forsee is in passing more than one selection from the checkbox, but once I get the code down I think I should be able to figure that out. Thanks.

Upvotes: 0

Views: 315

Answers (1)

Code Jammr
Code Jammr

Reputation: 1867

Your error message makes total sense. Try this

 var testViewModel = new TestViewModel
 {
     SomeCheckBox = new List<string> {TestViewModel.RadioButtonValues.Value1.ToString() }
 };

Upvotes: 1

Related Questions