How to disable binding of the route values in ASP.NET MVC?

后端 未结 2 1575
悲哀的现实
悲哀的现实 2021-01-14 10:30

As I know ValueProviderDictionary takes values for binding from 3 places

  1. From Post form
  2. From Route values
  3. From Query string

I

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 11:18

    I've made Action attribute and ValueProvider for solving this problem. Named it GetValuesAttribute and StrictValueProviderDictionary resp. You can set the source Form, RouteData or QueryString. For example if you want that ValueProvider would search for values in Form and maybe QueryString write the following above your method or controller:

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

    The source code is placed here: http://codepaste.net/2kpzct. The only problem is that it won't work if you'll want to get populated model as a parameter.

提交回复
热议问题