0

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"})

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Changing the parameter name seemed to do the trick, barring that it doesn't break something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.