tags:

views:

164

answers:

1

I am using asp.net mvc.

here I am not asking on controller logic but at view page.And I am not messing with default setting of url routing.

I have a view having some url like /controller/action?CID=2

In this view I want to put Link having above structure but with different controller.

The point is get the current url parameter and put hyperlink with same Querystring parameter.

+2  A: 
<%=Html.ActionLink("linkText", "actionName", 
    "controllerName", new {CID = Request.QueryString["CID"]}, null) %>

Do you mean something like this?

çağdaş
Is this an "okay" thing to do in MVC? I'm not saying you're wrong, I'm just interested to know.
Kezzer
@Kezzer Yes, the `Html` object is part of the MVC framework.
Daniel A. White
Actually your url format is not registered in my routing table. so I explicitly pass it like ?CID=1
Vikas
The third parameter on this overload is routeValues, and a custom object like the one above is usually what's used for this purpose (passing parameters for the route).
çağdaş
@VikasMy url format? I just put them in there for demonstration. You, of course, need to replace them with your values.
çağdaş
Vikas
Ok it's working! Thanks and sorry for commenting without checking
Vikas
No problem :) Glad that it worked.
çağdaş