MVC: Strongly typed ViewData without a code-behind file.(squaredroot.com)

submitted by TroyMGTroyMG(2670) 4 years, 1 month ago

Want to use strongly typed ViewData in your view without a code-behind file? It isn't quite as straight-forward as you'd think. Read on for the answer and a quick lesson in how the CLR interacts with generics.

5 comments |category: |Views: 202

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by powerrushpowerrush(3873) 4 years, 1 month ago 0

I hope the next CTP offers a more elegant solution.

Reply

posted by TroyMGTroyMG(2670) 4 years, 1 month ago 0

powerrush - Keep in mind this isn't really a MVC issue as much as an issue with how ASP.Net in general parses the "Inherits" attribute. It is just much more likely you'll encounter this issue while using the MVC framework.

Reply

posted by powerrushpowerrush(3873) 4 years, 1 month ago 0

I just meant I hope the MVC team recognizes the scenario of not using a code behind when [re]considering supported intention of a typed ViewData.

Reply

posted by TroyMGTroyMG(2670) 4 years, 1 month ago 0

That's a good point. Hopefully it isn't too difficult to change the way the Inherits attribute works. If it affects backwards compatability though, we're probably looking at a .Net 4.0 change at best...

Reply

posted by fquednaufquednau(404) 4 years, 1 month ago 0

You can check out Castle Windsor documentation as wellin the part about specifying a component implementing a generic interface - same fun. Write this a few times in your configuration file and your eyes start to bleed.

Reply

information Login or create an account to comment on this story