ASP.NET MVC - ASPX with non-default constructor

Posted by bh213 on Stack Overflow See other posts from Stack Overflow or by bh213
Published on 2009-07-30T10:16:07Z Indexed on 2010/06/07 10:02 UTC
Read the original article Hit count: 275

Is it possible for a ASPX view (in ASP.NET MVC) to have non-default constructor AND use this constructor when creating this view?

Example - Page will inherit from this class:

public class ViewPageWithHelper<TModel> : System.Web.Mvc.ViewPage<TModel> where TModel : class
    {
        public ViewPageWithHelper(Helpers helpers)
        {
            Helpers = helpers;
        }

        protected Helpers Helpers { get; private set; }
    }

ASPX view:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="MyInjectedViewPage<MyModel>" %>

<% Helpers.XXXX %>

Now, I'd like to inject Helpers into view somehow - automatically. Ideas?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about asp.net-mvc