I use the following code (taken from a Stackoverflow post: Action Image MVC3 Razor ) in the HTML extension helper to create an action link. My Url.Action () method returns a URL that has routeValues โโboth on the route and the URL, for example:
/Proposals/List/Tabled?id=Tabled
when i want just
/Proposals/List?id=Tabled
Any suggestions on why he wants to do this?
Update
Route rule from my Global.asax file. That must be why he does it, but why it doubles is still a mystery to me.
routes.MapRoute( _ "ProposalsList", _ "Proposals/List/{status}", _ New With {.controller = "Proposals", .action = "List", .status = "Pending"} _ )
Update
Here is my method call, and I added the method definition to the code below.
@Html.ActionImage("Proposals", "List", New With {.id = Model.StatusFilter}, "~/images/" + Model.ImageFile, "Count", 32, 32, Model.ProposalsCount.ToString + " " + Model.StatusFilter + " Proposal(s)")
Here is my code:
<Extension()> _ Public Function ActionImage(ByVal html As HtmlHelper, ByVal controller As String, ByVal action As String, ByVal routeValues As Object, ByVal imagePath As String, ByVal alt As String, ByVal width As Integer, ByVal height As Integer, ByVal text As String) As MvcHtmlString Dim url = New UrlHelper(html.ViewContext.RequestContext) Dim imgHtml As String Dim anchorHtml As String Dim imgbuilder = New TagBuilder("img") imgbuilder.MergeAttribute("src", url.Content(imagePath)) imgbuilder.MergeAttribute("alt", alt) imgbuilder.MergeAttribute("width", width) imgbuilder.MergeAttribute("height", height) imgHtml = imgbuilder.ToString(TagRenderMode.SelfClosing) Dim anchorBuilder = New TagBuilder("a") anchorBuilder.MergeAttribute("href", url.Action(action, controller, routeValues)) anchorBuilder.InnerHtml = imgHtml + "<br/>" + text anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal) Return MvcHtmlString.Create(anchorHtml) End Function