views:

429

answers:

1

I have a set of drop down controls on a view that are linked to two lists.

//control
ViewData["Countries"] = new SelectList(x.getCountries().ToList(), "key","value",country);
ViewData["Regions"] = new SelectList(x.getRegions(country).ToList(), "id", "name", regions);

/*
on the view
*/

<% using (Html.BeginForm("","", FormMethod.Get))
           { %>
           <ol>
               <li>
                <%= MvcEasyA.Helpers.LabelHelper.Label("Country", "Country:")%>
                <%= Html.DropDownList("Country", ViewData["Countries"] as SelectList) %>
                <input type="submit" value="countryGO" class="ddabtns" />
               </li>
               <li>
                <%= MvcEasyA.Helpers.LabelHelper.Label("Regions", "Regions:")%>
                <%= Html.DropDownList("Regions", ViewData["Regions"] as SelectList,"-- Select One --") %>
                <input type="submit" value="regionsGO" class="ddabtns" />
               </li>
           </ol>     
                <br />
                <input type="submit" value="go" />
<% } %>

So its sending a query to the same page (as its only really there to provide an alternative way of setting/updating the appropriate dropdowns, this is acceptable as it will all be replaced with javascript).

The url on clicking is something like... http://localhost:1689/?Country=FRA&amp;Regions=117

Regions is Dependant on being passed the country code.

I'm trying to achieve this bit without bothering with routing as there's no real point with regards this function.

So the Controller has the following method.

public ActionResult Index(string country, int regions)

I've tried

public ActionResult Index([Optional] string country, [Optional] int regions)

Which doesn't do the job.

+6  A: 

The string should be ok, as it'll get passed as an empty string. For int, make it nullable:

public ActionResult Index(string Country, int? Regions)

Also, you'll note I capitalized it in the same was as your querystring.

James S
Thanks for saving me from my self!
Chris M