Note that there are some explanatory texts on larger screens.

plurals
  1. POC# ASP.NET MVC 2 basic routing
    primarykey
    data
    text
    <p>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.</p> <p>A user is supposed to give 3 parameters (<code>string</code>, <code>bool</code>, <code>bool</code>). So I have a small form on my index page:</p> <pre><code> &lt;% using (Html.BeginForm("search", "Home")) { %&gt; &lt;label &gt;Name: &lt;/label&gt;&lt;br /&gt; &lt;input type="text" id='ml' name='ml' /&gt;&lt;br /&gt; &lt;label &gt;Sort members alphabethic? &lt;/label&gt; &lt;input type="checkbox" id='sortalph' name='sortalph' /&gt;&lt;br /&gt; &lt;label &gt;Number the list? &lt;/label&gt;&lt;input type="checkbox" id='number' name='number' /&gt;&lt;br /&gt; &lt;input type="submit" value='Submit'/&gt; &lt;% } %&gt; </code></pre> <p><code>Global.asax.cs</code> is set up like this:</p> <pre><code> 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 ); </code></pre> <p>The start of the <code>Search</code> method in my <code>HomeController</code> looks like this:</p> <pre><code>public ActionResult Search(string ml, bool? sortalph, bool? number) { if (sortalph == null) { sortalph = false; } if (number == null) { number = false; } </code></pre> <p>When I debug <strong><code>sortalph</code> and <code>number</code> are always <code>null</code></strong>. I'm not sure why.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload