This example has a helper class, a model class, MVC controller and the view. In the view I will show the string, loop over the list in a foreach loop and display the value from a bool.
Below is the code for the helper class:
Now we have the code for the model class:
As you can see in the code examples above, I have an IEnumerable string that contains my list of dogs, I also have a test string and bool each returning values.
In the controller, you will see I have created a new view model and I'm populating the values of the model with my tuple values and also filtering the list to display only 'German Shepherd' before passing the view model to the view.
The code for the view is below:
If we now run the code, you can see that the homepage now shows the return values that we have entered, this example uses hard-coded values, but we could have just as easily returned the data from a database or XML file.
If you found this example helpful, please leave a comment below.