MVC Question

Hey all!

My boss just tossed me onto an MVC project. I do not know how to do MVC. Hilarity ensues…

All I want (at the moment) is a drop down with three options. I’m mimicking the code he has in the view and controller. Here’s my controller code:


List<SelectListItem> rankings = new List<SelectListItem>();

SelectListItem ranking1 = new SelectListItem();
SelectListItem ranking2 = new SelectListItem();
SelectListItem ranking3 = new SelectListItem();

ranking1.Text = "Yes";
ranking1.Value = "Yes";

ranking2.Text = "No";
ranking2.Value = "No";

ranking3.Text = "Maybe";
ranking3.Value = "Maybe";

rankings.Add(ranking1);
rankings.Add(ranking2);
rankings.Add(ranking3);

SelectList rankingList = new SelectList(rankings);
ViewData["Ranking"] = rankingList;

View nugget:


<p id="changeRanking">Change Ranking to <%= Html.DropDownList("Ranking",(SelectList)ViewData["Ranking"], "~ select ranking ~") %></p>

The excessive instantiation is just me trying desperately to make something work.

I get a drop down with System.Web.MVC.SelectListItem instead of text and values. I’ve been researching this, but, like I said, I have no idea what I’m doing with MVC. What did I do wrong?

Thanks!

Found the problem. It needs to be this:

SelectList rankingList = new SelectList(rankings,“Value”,“Text”);

I assumed it would know Value and Text on its own, but apparently not.