开发者

Asp.Net MVC - HTML.ActionLink - HowToGoTo - Client/Index/A - route

开发者 https://www.devze.com 2023-04-03 08:27 出处:网络
This is in my route (works) routes.MapRoute(\"ClientIndexAndSubstringChar\", _ \"{controller}/{action}/{FirstChar}\", _

This is in my route (works)

    routes.MapRoute("ClientIndexAndSubstringChar", _
                    "{controller}/{action}/{FirstChar}", _
                    New With {.char = "[a-zA-Z0-9]"})

This is in my controller (works)

   Function Index(Optional ByVal KlantenSet As List(Of Domain.Slave.Klant) = Nothing, Optional FirstChar As Char = Nothing, Optional format As String = "html") As ActionResult
     //Some Code
    End Function

This is my View (doesn't link corre开发者_如何学Pythonctly)

@If ViewBag.ClientsLetters IsNot Nothing Then
  For Each ClientLetter As String In ViewBag.ClientsLetters
    @<div class="ClientsLetter">
      @Html.ActionLink(ClientLetter, "Index", "Client", New With {.FirstChar = ClientLetter})
    </div>
   Next
 End If

The ActionLink is wrong....

What should i do to fix it? My link links to : http://localhost:52254/Client/Index.html?Length=6 Instead of http://localhost:52254/Client/Index/A


Your action link

@Html.ActionLink(ClientLetter, "Index", "Client", New With {.FirstChar = ClientLetter})

The parameters here match this http://msdn.microsoft.com/en-us/library/dd504972.aspx

Should be something like this

@Html.ActionLink(ClientLetter, "Index", "Client", New With {.FirstChar = ClientLetter}, Null)

These parameters match this http://msdn.microsoft.com/en-us/library/dd493068.aspx

For the MapRoute I think you can do this:

routes.MapRoute("ClientIndexAndSubstringChar", _
                "{controller}/{action}/{FirstChar}")

Just get rid of that last parameter. Try it and see what it does.

0

精彩评论

暂无评论...
验证码 换一张
取 消