asp.net mvc - Dynamic typed ViewPage -


Is this possible? Here's what I'm trying to do:

  Public Action Index () {dynamic p = new {name = "test", phone = "111-2222"}; See Return (P); }  

and then my view System.Web.Mvc.ViewPage & gt; Dynamic & gt; and attempts to print Model.Name.

I am getting an error: '& lt;> f__AnonymousType1.Name' is not out of reach due to its security level

So basically, am I just not possible Am trying to do

  & lt;% @ page title = "" language = "c #" masterpage file = "~ / view / shared" site.master "inheritance =" system. Web. MVC .View page & gt; Dynamic & gt; "& Gt%; & lt; asp: Content ... & gt; & lt;% = Model.Name%> & lt;% = Model.Phone% & gt; & lt; / ASP: Content & gt; ;  

The view is built into the constructor frame.

anonymous type Can not be backed by a method; They are only valid within the scope of the law in which they are defined.

You should use a model class that you have defined before and it Has passed in your view.

Update :

I think I was wrong before, nothing wrong in passing a model class. Do you have more code to post? Look especially and its creator

Update another:

OK, I have an anonymous type To use it as a dynamic variable was wrong about anonymity in any other way - which Can be.

But I believe it was wrong that you're trying to work it will work. Unfortunately for you, this will not happen. The problem is that you can see the ViewPage & lt; TModel & gt; , which internally ViewDataDictionary & lt; TModeel & gt; because they require strong type, you will not be able to use dynamic objects with them. The internal structure just does not use internal mobility, and the dynamic specifies if type fails.

A DynamicViewPage class and the respective DynamicViewDataDictionary class which accepts object and it's an internal form of dynamic Stores in Then you can use an anonymous type and send it to your views

She said, you will not achieve anything you will be able to designate your thoughts as your name (i.e. & lt;% = Model.Name% & gt; ), but you will not benefit from strong typing. There will be no difference and there will be no protection. You also want to use Dennis Palmer as well as in-built ViewDataDictionary as well.

This is an interesting (and, unfortunately, for me, absorbed), but I think that eventually, it is not going to be like this. Either make a public type announcement and pass it on to your views, or use the undocumented dictionary


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -