asp.net mvc - value provider and collections -


i'd access in actionfilter property. propert collection.

usually access values using valueprovider this

filtercontext.controller.valueprovider.getvalue("prop"); 

but isn't working in case of collection.

is there way collection ?

you use filtercontext.actionparameters. example:

model:

public class myviewmodel {     public ienumerable<string> collection { get; set; } } 

action filter:

public class myactionfilterattribute : actionfilterattribute {     public override void onactionexecuting(actionexecutingcontext filtercontext)     {         var value = filtercontext.actionparameters["model"];         // todo: value         base.onactionexecuting(filtercontext);     } } 

controller:

public class homecontroller : controller {     [myactionfilter]     public actionresult index(myviewmodel model)     {         return view();     } } 

request: /?collection[0]=foo&collection[1]=bar


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -