c# - How to get a ViewModel entity by using the name from a string value? -


so have viewmodel called

sampleviewmodel

which contains 3 entities called

entityone

entitytwo

entitythree

now have action in controller action looks little bit this

public actionresult testaction(string destination) {      sampleviewmodel sampleviewmodel = new sampleviewmodel(); } 

now want able select particular entity depending on string "destination" set as. destination rather set "entityone", "entitytwo" or "entitythree". want call

sampleviewmodel.entityone 

if string contains "entityone".

so in affect saying

sampleviewmodel.destination //where destination equal 1 entity in viewmodel 

how can this?

thanks

you can use reflection get, assume have class entity in here:

var entity = (entity) typeof (sampleviewmodel)                              .getproperty(destination)                              .getvalue(sampleviewmodel); 

Comments