Action filters to supply common data to Views in ASP.NET MVC 4 -


i'm trying common properties views derive viewmodelbase. except ran sort of catch-22...

the common properties of viewmodelbase are: user , environment (there more, question these 2 suffice).

right now, have global filter assigns these 2 properties - viewmodelbase.user property assigned basecontroller.user, assigned authorization filter.

it works in cases, this: authorization filter times based on business logic decides redirect user "not yet approved" page. done so:

var notapprovedview = new viewresult(); notapprovedview.viewname = "notyetapproved"; filtercontext.result = notapprovedview; 

except, in case, viewmodel not yet have common property supposed assigned global filter, results in run-time exception.

what's proper (i.e. best practice, not hack) way deal situation need common properties assigned , of common properties may change depending on authorization?

thanks.

i think may have missed forest trees on one... sorry.

i following in authorization filter:

var notapprovedview = new viewresult(); notapprovedview.viewname = "notyetapproved";  // add line     notapprovedview.model = new viewmodelbase(){user = this.user};  filtercontext.result = notapprovedview; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -