ASP.NET MVC ViewData (using indexes)

I had a working solution using ASP.NET MVC Preview 3 (was improved from the Preview 2 solution), which uses the untyped ViewMasterPage:

public partial class Home : ViewMasterPage

Home.Master has a display instruction as follows:

<%= ((GenericViewData)ViewData["Generic"]).Skin %>

However, the developer on the team simply changed the assembly links to Preview 4.

After that, the code will no longer populate ViewData with indexed values, as described above.

Instead, ViewData ["Generic"] is null.

For this question , ViewData.Eval ("Generic") works, and ViewData.Model also populates correctly.

However, the reason this solution does not use printed pages, etc., is because it is a kind of legacy. Thus, it is not easy to go through this rather large solution and refresh all .aspx pages (especially since the compiler does not detect such things).

I tried to return the assembly by deleting the link, and then adding the link to the Preview 3 assembly in the project's β€œbin” folder. This has not changed anything. I even tried to return the project file to an earlier version and did not seem to fix the problem.

I have other solutions using the same technique that continues to work.

Is there anything you can say about why this suddenly stopped working and how I can fix it (any hint in the right direction would be appreciated)?

+1
5

, []. Eval() . , .

+1

ViewData [ "blah" ] ViewData.Eval( "blah" ). , , :

  • , .
  • .
  • , , .
0

viewdata? :

:

ViewData["CategoryName"] = a.Name;

:

<%= ViewData["CategoryName"] %>

, Preview 5. 3 4...

0
source

Re: Ricky

I just pass the object when I call the View () method from the controller.

I also noticed that on my deployed server, where nothing was updated, ViewData.Eval does not work and ViewData ["index"] works.

On my development server, ViewData ["index"] is not working and ViewData.Eval is working ...

0
source

Yes, so everything that you go into the view is available in the View as ViewData.Model. But it will be just a good old object if you do not make strongly typed representations ...

0
source

Source: https://habr.com/ru/post/1750959/


All Articles