public static ModelSource <TEntity> InvokeModelSource <TEntity>(this TempDataDictionary tempData) where TEntity : class, new() { GenericManager <BFDataContext> models = tempData.GetGenericModelSource(); if (models == null) { models = new ModelSource <TEntity>(); tempData.SetModelSource <TEntity>((ModelSource <TEntity>)models); return((ModelSource <TEntity>)models); } else if (models is ModelSource <TEntity> ) { return((ModelSource <TEntity>)models); } else { return(new ModelSource <TEntity>(models)); } }