MVC 3: ActionLink VB.Net

Posted by xamlnotes on Geeks with Blogs See other posts from Geeks with Blogs or by xamlnotes
Published on Thu, 10 Mar 2011 13:30:34 GMT Indexed on 2011/03/10 16:11 UTC
Read the original article Hit count: 240

Filed under:

Theres not a ton of good samples out there on using MVC with VB, so I am going to post some things that I am doing on a project.

Lets look at links. I am converting a asp classic app to mvc.  One page has an anchor tag which I modified to look like so to point to a controller action:

<A style=color:red; HREF='Detail/" & currentItem.IdNumber & "'>" & currentItem.IdNumber & "</A>

This resolves out to what looks like the right URL and in fact the detail action is fired. The actions signature looks like so:

Function Detail(ByVal IdNumber As String) As ActionResult

But, IdNumber would always be blank, it was never set to the id passed in the url.  Hmm.

So, I tried the following by using the ActionLink method of the html helper:

Html.ActionLink(currentLead.LeadNumber, "Detail", New With {.IdNumber = currentItem.IdNumber }) 

Viola! That worked fine and the Detail method parameter was set just like it should be.

Very interesting.

© Geeks with Blogs or respective owner