How to disable route value binding in ASP.NET MVC?

As I know, ValueProviderDictionary takes values ​​for binding from 3 places.

  • From the message form
  • From route values
  • From the query string

I want to disable the second and third options. The only solution that I see here is to create your own custom ValueProvider (copy-paste the original ValueProviderDictionary file and remove these two parameters from it).

Is this the right decision? Are there any more elegant alternatives?

(If the solution with the custom ValueProvider is correct where it should be initialized? In the controller action method or in the custom ModelBinder?)

thanks

+3
source share
2 answers

Action ValueProvider . GetValuesAttribute StrictValueProviderDictionary . , RouteData QueryString. , , ValueProvider Form , , QueryString, :

[GetValues(ValueSource.Form | ValueSource.QueryString)]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(FormCollection formValues)
{
   ...
   UpdateModel(myModel); //model will be updated from mentioned sources

: http://codepaste.net/2kpzct. , , .

+2

Controller.Initialize() ValueProvider ( base.Initialize()).

ValueProviderDictionary, . , ValueProviderDictionary.PopulateDictionary(). , . (), this.YourCustomPopulateDictionary(). .

+3

Source: https://habr.com/ru/post/1715744/


All Articles