I'm quite new to ASP.NET and C# and I'm having some issues with my routing. Was hoping someone would be so kind to help me out.
A user is supposed to give 3 parameters (string
, bool
, bool
).
So I have a small form on my index page:
<% using (Html.BeginForm("search", "Home")) { %>
<label >Name: </label><br />
<input type="text" id='ml' name='ml' /><br />
<label >Sort members alphabethic? </label> <input type="checkbox" id='sortalph' name='sortalph' /><br />
<label >Number the list? </label><input type="checkbox" id='number' name='number' /><br />
<input type="submit" value='Submit'/>
<% } %>
Global.asax.cs
is set up like this:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index"} // Parameter defaults
);
routes.MapRoute(
"Search", // Route name
"{controller}/{action}/{ml}/{sortalph}/{number}", // URL with parameters
new { controller = "Docent", action = "Search" } // Parameter defaults
);
The start of the Search
method in my HomeController
looks like this:
public ActionResult Search(string ml, bool? sortalph, bool? number)
{
if (sortalph == null)
{
sortalph = false;
}
if (number == null)
{
number = false;
}
When I debug sortalph
and number
are always null
. I'm not sure why.