How do I … ASP.Net MVC with VB.Net
18-Jun-1212 Leave a comment
How do I … submit text from an input box.
<form action="" method="post"> Code starts with: <input type="text" name="MinCode" id="CodeInput" /> <input type="submit" value="Click Me" /> </form>
and
<form id="search" action="http://www.google.co.uk/search" method="GET"> <input type="text" name="q" /> <input type="submit" value="Submit" /> </form>
How do I … Register Routes
routes.MapRoute("Products", "Products/{myCode}", _ New With {.controller = "Products", .action = "Search"})
How do I … use this route in a controller
Function Search(name As String) As ActionResult Dim myName = RouteData.Values("name") Dim myNameFromSignature = name Dim result = String.Concat(myName, vbCrLf, name) 'Return RedirectToAction("Index") Dim model As New List(Of ProductsModel) InitialiseProductList(model) model = model.Where(Function(f) f.Code.ToLower.StartsWith(name)).ToList If model.Count = 0 Then Return Content(Server.HtmlEncode("No results")) End If 'ViewBag.Name = name Return View(model) End Function
How do I now call this ASP.Net MVC Search Box
<% Html.BeginForm("Search", "Products")%> <input type="text" name="myCode" /> <input type="submit" name="Submit" /> <% Html.EndForm() %>
Confirmed that this works. SRS 18/06/2012. Then did not work 19/06/2012. However following did work.
this example also includes “How do I use @ in ASP.Net MVC including Using.
@Using (Html.BeginForm(“Search”, “Reg90″, FormMethod.Post))
@:<input type=”text” name=”myCode” />
@:<input type=”submit” value=”Click Me 2″ />
End Using