Beispiel #1
0
        internal virtual void RenderPartialInternal(
            string partialViewName,
            ViewDataDictionary viewData,
            object model,
            TextWriter writer,
            ViewEngineCollection viewEngineCollection
            )
        {
            if (String.IsNullOrEmpty(partialViewName))
            {
                throw new ArgumentException(MvcResources.Common_NullOrEmpty, "partialViewName");
            }

            ViewDataDictionary newViewData = null;

            if (model == null)
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary(ViewData);
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData);
                }
            }
            else
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary(model);
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData)
                    {
                        Model = model
                    };
                }
            }

            ViewContext newViewContext = new ViewContext(
                ViewContext,
                ViewContext.View,
                newViewData,
                ViewContext.TempData,
                writer
                );
            IView view = FindPartialView(newViewContext, partialViewName, viewEngineCollection);

            view.Render(newViewContext, writer);
        }
Beispiel #2
0
        protected override ViewEngineResult FindView(ControllerContext context) {
            ViewEngineResult result = ViewEngineCollection.FindView(context, ViewName, MasterName);
            if (result.View != null) {
                return result;
            }

            // we need to generate an exception containing all the locations we searched
            StringBuilder locationsText = new StringBuilder();
            foreach (string location in result.SearchedLocations) {
                locationsText.AppendLine();
                locationsText.Append(location);
            }
            throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture,
                MvcResources.Common_ViewNotFound, ViewName, locationsText));
        }
Beispiel #3
0
        public Email(string viewName) : base(viewName)
        {
            var tt = typeof(Email).Assembly;

            var engines = new System.Web.Mvc.ViewEngineCollection {
                new ResourceRazorViewEngine1(typeof(Email).Assembly, @"WatchRecruit.Web.Util.Views")
            };
            //engines.Add(new FileSystemRazorViewEngine(viewsPath));


            var smtpServerUserName = ConfigurationManager.AppSettings["SmtpUsername"];
            var smtpServerPassword = ConfigurationManager.AppSettings["SmtpPassword"];

            var client = new SmtpClient();

            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials    = new NetworkCredential(smtpServerUserName, smtpServerPassword);
            client.EnableSsl      = true;
            emaiService           = new Postal.EmailService(engines, () => client);
            //emaiService = new Postal.EmailService(System.Web.Mvc.ViewEngines.Engines, () => client);
        }
Beispiel #4
0
        internal static IView FindPartialView(ViewContext viewContext, string partialViewName, ViewEngineCollection viewEngineCollection)
        {
            ViewEngineResult result = viewEngineCollection.FindPartialView(viewContext, partialViewName);

            if (result.View != null)
            {
                return(result.View);
            }

            StringBuilder locationsText = new StringBuilder();

            foreach (string location in result.SearchedLocations)
            {
                locationsText.AppendLine();
                locationsText.Append(location);
            }

            throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture,
                                                              MvcResources.Common_PartialViewNotFound, partialViewName, locationsText));
        }
        private IView GetView(string partialViewName, ViewDataDictionary viewData, object model, TextWriter writer, ViewEngineCollection viewEngineCollection, out ViewContext newViewContext)
        {
            if (String.IsNullOrEmpty(partialViewName))
            {
                throw new ArgumentException(MvcResources.Common_NullOrEmpty, "partialViewName");
            }

            ViewDataDictionary newViewData = null;

            if (model == null)
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary(ViewData);
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData);
                }
            }
            else
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary(model);
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData)
                    {
                        Model = model
                    };
                }
            }

            newViewContext = new ViewContext(ViewContext, ViewContext.View, newViewData, ViewContext.TempData, writer);
            var view = FindPartialView(newViewContext, partialViewName, viewEngineCollection);

            return(view);
        }
        internal virtual Task RenderPartialInternalAsync(string partialViewName, ViewDataDictionary viewData, object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
        {
            ViewContext newViewContext;
            var         view = GetView(partialViewName, viewData, model, writer, viewEngineCollection, out newViewContext);

            return(view.RenderAsync(newViewContext, writer));
        }
        internal virtual void RenderPartialInternal(string partialViewName, ViewDataDictionary viewData, object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
        {
            ViewContext newViewContext;
            var         view = GetView(partialViewName, viewData, model, writer, viewEngineCollection, out newViewContext);

            view.Render(newViewContext, writer);
        }
 internal static void RegisterViewEngines(System.Web.Mvc.ViewEngineCollection viewEngineCollection)
 {
     ViewEngines.Engines.Clear();
     ViewEngines.Engines.Add(new RazorViewEngine());
 }