0

I have tried the pluggable structure as discussed in this post: Pluggable MVC view return null

It is also explained in this post: http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/

When I try to access ViewBag/Model in one of the area, it gives me this error:


  • The name 'ViewBag' does not exist in the current context

  • The name 'model' does not exist in the current context***

Community
  • 1
  • 1
  • If you want a hassle free plugin system read my blog article: http://blog.gauffin.org/2012/05/griffin-mvccontrib-the-plugin-system/ – jgauffin Jan 03 '13 at 06:36

1 Answers1

1

Since you are serving the view from an unknown location there's no longer the ~/Views/web.config that applies to it. And as you know inside this file is specified the base type for Razor views (System.Web.Mvc.WebViewPage). So one possibility is to add an @inherits directive to the top of your view:

@inherits System.Web.Mvc.WebViewPage
@model MyViewModel

<div>@ViewBag.FooBar</div>

Side-note: since you already have a view model why even care about ViewBag? Why not get rid of it?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks for the reply Darin. It did not help in fact. I must be doing something crazy. This is just a proof of concept to make some basis to port my project from composite web application blocks to areas. So I need to cover both viewbag and models. – Satjinder Singh Bath Jan 03 '13 at 21:11
  • Well, this has always worked for me. I am afraid that without showing your code and an example that would allow us to reproduce the problem you are having it's close to impossible to help you further. – Darin Dimitrov Jan 03 '13 at 21:26