2

My controller has an object as parameter

Function Search(ByVal model As ItemSearchModel) As ActionResult

Which look something like this

Public Class ItemSearchModel

    Public Property SearchQuery As String

And, as you can imagine, the url will look this like

/Search?SearchQuery=test

I want to change the query string to have a small variable, sort of like

/Search?s=test

Is there a built-in way I could keep the same variable name in my class? Something like

Public Class ItemSearchModel

    <QueryString(Name:="s")> _
    Public Property SearchQuery As String

2 Answers 2

4

I think you can use the ActionParameterAlias package from Nuget to accomplish what you want.

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

Comments

1

You can define two properties, both pointing to the same field. Then you can access that item using either s or SearchQuery from the URL.

Public Class ItemSearchModel
    Private _s As String

    Public Property s() As String
        Get
            Return _s
        End Get
        Set(value As String)
            _s = value
        End Set
    End Property
    Public Property SearchQuery() As String
        Get
            Return _s
        End Get
        Set(value As String)
            _s = value
        End Set
    End Property
End Class

Comments

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.