0

I have a search form which has some default text Type your search phrase here which currently gets sent as a querystring parameter - the generated URL looks like so:

/search?KeyWords=Type+your+search+phrase+here

However I would like to remove it from the querystring altogether.

At what point should I remove it? I mean, I can check in the controller whether the string matches, and not use it as keywords for the search, but it is still present in the URL and ideally I would like it to be removed entirely so as not to cause any confusion (plus it looks pretty bad having the default phrase in the URL!).

1
  • I'm not sure how to answer the main part of your question, but wouldn't you change the routing of your app to redirect to the default 'search phrase' value so you can have a clean default url? Something like what is discussed here: stackoverflow.com/a/968927/1026898 ? Commented Sep 10, 2012 at 16:24

1 Answer 1

1

The semantically correct way to have a default value for a text input field is to use the the HTML5 placeholder attribute instead of setting the value attribute:

@Html.TextBoxFor(x => x.Foo, new { placeholder = "Type your search phrase here" })

In this case the default value won't be sent when the form is submitted.

And if you need to support legacy browsers you could use the jquery.placeholder plugin which will unobtrusively enable support for it.

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.