How do I … ASP.Net MVC with VB.Net

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: