1

The Question

Is there a way to alias the parameters generated by MVC, in my case it would be the searchTerm param? For example, in my viewmodel it would still be SearchViewModel.searchTerm but the URL would look more like /Home/Search?s=jimmy

Search Form

<% using (Html.BeginForm("Search", "Home", FormMethod.Get)) {%>
       <%: Html.TextBoxFor(model => model.searchTerm) %>
       <input type="submit" value="Search" />
<% } %>

View Model

    public class SearchViewModel
    {
        public string searchTerm { get; set; }
    }

The URL Generated

/Home/Search?searchTerm=jimmy

Edit: Doesn't seem possible. Looks like I'll have to do it on my own..

1 Answer 1

2

I think you could either change your textbox control to not use templating and use the name your want to see in the query string like this...

<%= Html.TextBox("s", Model.searchTerm) 

Or you could change the template that the TextBoxFor method uses with a own custom one, but I'm not sure what convention you would use. Maybe check for modelnames of "searchTerm"?

This site has some examples of how to create a custom template.

Sorry, if the syntax was not correct in the code, but I do not have MVC on this machine.

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

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.