【问题标题】:Call to void method from static method in webform从 webform 中的静态方法调用 void 方法
【发布时间】:2015-12-19 05:23:15
【问题描述】:

我的 asp.net mvc 5 项目中有以下文件夹结构。我可以在我的 cshtml 视图页面中使用 jquery 脚本调用和传递参数 OnSubmit() webmethod。

现在我想从 OnSubmit() webmethod 调用 ShowReport() void 方法 .this ShowReport() 方法我用来显示 RDLC 报告向导

我该怎么做

这是我的网络表单代码隐藏文件的摘要 Incomplete_Prodcut.aspx.cs

public partial class Incomplete_Prodcut : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }       

        /// Method to show RDLC report 
        public void ShowReport()
        {
            //Reset
            ReportViewer1.Reset();

            //DataSource
            DataTable dt = GetData(type.Text, category.Text, subsidary.Text, country.Text, dateHERE.Text);

            .............

        }


        public DataTable GetData(string type, string category, string country, string subsidary, string dateHERE)
        {
            ...............

            return dt;
        }

        [WebMethod]    
        public static string OnSubmit(string type, string category, string country, string subsidary, string dateHERE)
        {

            return "";
        }


    }

【问题讨论】:

    标签: c# asp.net-mvc webforms code-behind webmethod


    【解决方案1】:

    您正在从静态方法调用非静态方法。这只能通过初始化类并调用其非静态方法来实现。

    如果您在理解静态和非静态方法之间的区别时遇到问题,这里有一个简短的解释。

    What's a “static method” in C#?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多