Telerik ASP.NET AJAX Controls in MVC project Part ||

by Rok Bermež 3. September 2010 15:09

Some controls explicitly require to be placed within

tag. To go around this issue you can do something like this (telerik reporting used in MVC project):
public class NoServerFormPage: Page
        {
            public override void VerifyRenderingInServerForm(Control control)
            {
                // to avoid the server form (<form runat="server">) requirement
            }
        }
        
        public static MvcHtmlString TelerikReport(this HtmlHelper htmlHelper, object  value, object htmlAttributes )
        {
            NoServerFormPage page = new NoServerFormPage();
            RadMvcScriptManager mvcScriptManager = new RadMvcScriptManager();
            mvcScriptManager.EnableViewState = false;
            page.Controls.Add(mvcScriptManager);
            RadStyleSheetManager radStyleSheetManager = new RadStyleSheetManager();
            page.Controls.Add(radStyleSheetManager);

            ReportViewer reportViewer = new ReportViewer();
            reportViewer.ID = "whoCares";
            reportViewer.Height = 890;
            reportViewer.Width = 700;
            
            reportViewer.ToolbarVisible = true;
            reportViewer.Report = new Ntk.Reports.Racun();
            ((Telerik.Reporting.Report)reportViewer.Report).ReportParameters["ID"].Value = value;
            reportViewer.Resources.CurrentPageToolTip = "Trenutna stran";
            reportViewer.Resources.ExportButtonText = "Izvozi";
            reportViewer.Resources.ExportSelectFormatText = "Izberi format za izvoz";
            reportViewer.Resources.ExportToolTip = "Izvoz";
            reportViewer.Resources.FirstPageToolTip = "prva stran";
            reportViewer.Resources.LabelOf = "od";
            reportViewer.Resources.LastPageToolTip = "Zadnja stran";
            reportViewer.Resources.NextPageToolTip = "naslednja stran";
            reportViewer.Resources.PreviousPageToolTip = "prejšnja stran";
            reportViewer.Resources.PrintToolTip = "Natisni";
            reportViewer.Resources.ProcessingReportMessage = "Nalagam...";
            reportViewer.Resources.RefreshToolTip = "Osveži";
            

            page.Controls.Add(reportViewer);
            StringWriter output = new StringWriter();
            HttpContext.Current.Server.Execute(page, output, false);

            return MvcHtmlString.Create(output.ToString());
        }

Tags:

.Net | c# | ASP.NET | Web

Add comment

Calendar

<<  June 2018  >>
MonTueWedThuFriSatSun
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar

Page List

Month List