ek_ny
ek_ny

Reputation: 10243

Creating Action Links With Special Characters

I'm trying to create an action link which has a url parameter with a period. I can do this the following way:

        <a href="/@(tab)Profile/Index?selected=@(tab)&DatingProfile.ProfileId=@(Model.DatingProfile.ProfileId)" selectedTab=@tab>@tab</a>

yet, I can't do it with an ActionLink:

        @Html.ActionLink(tab, String.Format("{0}Profile", tab), new{selected=tab,DatingProfile.Id=Model.DatingProfile.ProfileId}, {selectedTab = tab}) 

I get the following compilation error: CS0746: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

Any ideas how I can get this to work with an Action Link?

Upvotes: 2

Views: 787

Answers (1)

Electrionics
Electrionics

Reputation: 6772

Anonymous types, that used in ActionLink method for route parameters don't allow names with '.' character - it's C# feature - you can't change this. But you can use next:

@Html.ActionLink(tab, string.Format("{0}Profile", tab), new RouteValueDictionary { { "selected", tab }, { "DatingProfile.ProfileId", Model.DatingProfile.ProfileId } }, new Dictionary<string, object> { { "selectedTab", tab } })

Upvotes: 1

Related Questions