I want to use a LinqDataSource or ObjectDataSource with ViewData.Model, where ViewData.Model is an string array.
I don’t want to bind the datasource on view’s PageLoad event.
Is it possible? How?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should NOT return the actual datasource into your view since that would break the whole MVC concept. Instead you should return data objects from the source via the controller in order to have a clean separation of the model internals and the view.
However if you really want to return your data source this is how you do it, it is the same way as with any kind of object you want: in your controller you return a new view with the object as a parameter. That object will become available via the view’s Model property.
I.e. in your controller action have the following:
In your view you can call the
Modelproperty directly and accessyourDataSource. You’ll need to type cast it if you haven’t typed your view like this: