2

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?

ek_ny
  • 10,153
  • 6
  • 47
  • 60

1 Answers1

1

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 } })
David Levin
  • 6,573
  • 5
  • 48
  • 80