Ich habe Formular Produkte suchen:So verwenden @ Html.BeginRouteForm für Suchformular
@using (Html.BeginForm("Search", "Results", FormMethod.Get, htmlAttributes: new { @class = "navbar-form navbar-left", role = "search" }))
{
<div class="form-group">
<input type="text" name="txtSearch" class="form-control" placeholder="Products name..." />
@Html.DropDownList("CategoryId", null, "Select category", new { @class = "form-control" })
<select class="form-control" id="FromPrice" name="FromPrice">
<option value="0">From price</option>
<option value="2000000">2,000,000d</option>
<option value="4000000">4,000,000d</option></select><select class="form-control" id="ToPrice" name="ToPrice">
<option value="0">To price</option>
<option value="2000000">2,000,000d</option>
<option value="4000000">4,000,000d</option>
<option value="6000000">6,000,000d</option>
</select>
<input type="submit" class="btn btn-danger form-control" value="Search" />
</div>
}
und eine Route in RouteConfig
routes.MapRoute(
name: "SearchForm",
url: "ket-qua/{txtSearch}-{CategoryId}-{FromPrice}-{ToPrice}",
defaults: new { controller = "Results", action = "Search"}
)
Datei Wie kann ich die Route "Searchform" nennen, wenn Ich gebe das Suchformular oben mit allen Parametern ein.
'@ Html.BeginRouteForm ("Searchform", FormMethod.Get)' aber die Werte werden als Query-String-Parameter hinzugefügt werden, nicht Route-Werte (Ihrem Browser nichts über Ihre Route Definitionen weiß), so erhalten Sie '/Ergebnisse/Suche? TxtSearch = abc & CategoryId = 2 & ..... ' –