Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bilal khan 35 posts 58 karma points
    Nov 27, 2014 @ 11:48
    Bilal khan
    0

    Zbu ModelBuilder and BaseController issues - please help!

    Hello, 

    I am using zbuModelBuilder to generate my Models. I am trying to use a BaseController that handles all the common elements (e.g. Page title, pageName etc).

    In my baseController I have a function called createViewModel that creates the generic T style model below is that function

            protected T CreateViewModel<T>(RenderModel model) where T : new(){

    var viewModel = (T)Activator.CreateInstance(typeof(T), model);

                return viewModel;

            }

    Now in my HomeController that extends from BaseController I am trying to call this function like so

     public override ActionResult Index(RenderModel model)

            {  var viewModel = CreateViewModel<Home>(model);

                return CurrentTemplate(viewModel);

            }

    but keep getting the following error

     must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 

    Any help will be greatly appreciated!..
    many thanks
    Ad
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 27, 2014 @ 12:09
  • Bilal khan 35 posts 58 karma points
    Nov 27, 2014 @ 12:54
    Bilal khan
    0

    Thank you very much I am lookig into this now - Looks like what I need!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 03, 2014 @ 17:34
    Jeroen Breuer
    0

    Hello,

    Did you succeed in getting this to work?

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft