コード例 #1
0
        static RazorTemplateHtmlHelper()
        {
            var templateConfig = new TemplateServiceConfiguration
            {
                Resolver = new DelegateTemplateResolver(name =>
                {
                    var stream = EmbeddedResourceRegistry.ResolveResourceStream(name);
                    using (var reader = new StreamReader(stream))
                    {
                        var inherits = "";
                        var sb       = new StringBuilder();
                        while (reader.Peek() > 0)
                        {
                            var readLine = reader.ReadLine();
                            if (readLine.StartsWith("@model "))
                            {
                                inherits = ("@inherits FormFactory.RazorEngine.RazorTemplateFormFactoryTemplate<" + readLine.Substring(7) + ">\r\n");
                                continue;
                            }
                            if (readLine == "@using FormFactory.AspMvc")
                            {
                                sb.AppendLine("@using FormFactory.RazorEngine");
                                continue;
                            }
                            sb.AppendLine(readLine);
                        }
                        return(inherits + sb.ToString());
                    }
                })
            };

            templateConfig.BaseTemplateType = typeof(RazorTemplateFormFactoryTemplate <>);
            Razor.SetTemplateService(new TemplateService(templateConfig));
        }
コード例 #2
0
        public IViewFinderResult FindPartialView(string partialViewName)
        {
            var viewName = EmbeddedResourceRegistry.ResolveResourcePath(partialViewName);

            if (viewName == null)
            {
                return(new RazorTemplateViewFinderResult());
            }
            return(new RazorTemplateViewFinderResult()
            {
                View = new RazorTemplateView()
            });
        }