mrshickadance
mrshickadance

Reputation: 1251

querystring in URL of MVC app

I am having trouble with building a URL with a query string. I have this code that does what I want it to:

formatoptions: { baseLinkUrl: '@Url.Action("UserInformation", "UserList")', idName: 'Id' }

This makes the proper URL (/UserInformation?Id=4)

This is the section that I am having trouble with, basically trying to replicate what is above, but the syntax is different and I am not sure what's wrong.

results.Add(New SearchResult With {.Link = Url.Action("UserInformation", "UserList", New With {.id = use.Id}), .Text = use.ToString, .Type = "User"})

This make the URL a bit off (/UserInformation/4), it causes problems when redirecting from that page. I'd like to edit this to replicate the proper URL string.

This is a bit of a hack that we figured out to make it work..but I'd like to do it 'properly' if possible

results.Add(New SearchResult With {.Link = Url.Content("~/UserList/UserInformation?Id=" & use.Id), .Text = use.ToString, .Type = "User"})

Upvotes: 0

Views: 769

Answers (1)

Mark Gibbons
Mark Gibbons

Reputation: 581

It's because of your default route having the Id as optional. You can either change the default route which might make all your other Url's look not as clean, or just pick a different parameter name for the Id on the UserInformation action such as userId.

Upvotes: 1

Related Questions