Shortening query names from the view model

I am looking for a way in my view models to shorten property names in the query string for a search form. For example, the variable name verbose may be a request, but you see q in querystring.

Currently, to achieve this goal, I am doing the following.

public string Query { get; set; } public string q { get { return Query; } set { Query = value; } } 

I would think that it would be easier if there was an annotation for the data to help with this.

 [Querystring(Name="q")] public string Query { get; set; } 

Is there a better way to do this that I don't think about, or is it possible to encode my own data annotations?

+8
c # asp.net-mvc viewmodel data-annotations
source share
1 answer

You need to create your own ModelBinder .

Take a look:

+3
source share

All Articles