views:

177

answers:

2

ok here goes, since my html.renderaction crashes my dev and prod servers i have to use partials(crap)

i tried creating public partial controller{} class so i can set needed data for all my views but i am having no luck (everything breaks)

i am coming from LAMP cakePHP background and really need simplicity.

i need to know how to create a partial base controller(that doesnt override the regular base controller) and how to access multiple models from the class.

thx

+2  A: 
public class BaseController: Controller
{
   public override OnActionExecuting(...) { ... }
   public override OnActionExecuted(... context) 
   {
       if (context.Result is ViewResult)
           ((ViewResult)context.Result).ViewData["mycommondata"] = data;
   }
   ...
}

public class MyController1: BaseController 
{
}

I.e. just derive from your new base controller class.

However I'd suggest you to ask here why your RenderPartial "crashes" - since it can be a better way for you, and it obviously shouldn't crash.

queen3
renderpartial works - its renderaction(futures) that crashesand i need multiple data sets in my views - looking at the view model pattern now - but i really miss cakePHP(i could have had this done by now)
rxhector
OK, RenderAction, but why and how it crashes? Why instead of fixing the problem you want something less suited for the problem? Also, if you need multiple data, why don't you use ViewData["data1"] = data1; ViewData["data2"] = data2. And, of course, you could have done this already; and if I had to write in CakePHP I'd say "I could have done this in ASP.NET MVC by now" ;-).
queen3
i tried setting viewdata['x'] and viewdata['y']viewdata['x'] is a single objectviewdata['y'] is a list i can pass viewdata['y'] to a partial view but singular viewdata['x'] throws errorsi am still troubleshooting why renderaction crashes everything - at least i am still going - its fun to learn 'the hard way'
rxhector
A: 

better way to create base controller

    public class Controller : System.Web.Mvc.Controller
{
    public shipsEntities db = new shipsEntities();

    public Controller()
    {
        ViewData["ships"] = db.ships.ToList();
    }
}

that way the rest of controllers follow regular convention

public class MyController : Controller
rxhector