从控制器方法调用文件(aspx.cs文件)后面代码中的方法
本文关键字:文件 方法 代码 aspx 控制器 调用 cs | 更新日期: 2023-09-27 18:13:12
我有以下控制器方法
public class ReportController : Controller
{
// GET: Report
public ActionResult Incomplete_Product_Report()
{
return View();
}
}
我想调用以下方法,这是ShowReport()在aspx web-form文件后面的代码。
private void ShowReport()
{
//DataSource
DataTable dt = GetData(type.Text, category.Text,subsidary.Text,country.Text, dateHERE.Text);
....................
}
private DataTable GetData(string type, string category, string country, string subsidary, string dateHERE)
{
................
}
then ShowReport()方法调用和传递参数调用GetData()
我有以下视图形式来过滤结果,http://s9.postimg.org/95xvv21z3/wewrwr.png
我也有以下aspx webform生成报告http://s7.postimg.org/iz4zdety3/44r3.png
一旦我在视图中单击"生成报告"按钮,我应该能够在webform中传递参数生成结果,并显示微软报告向导(RDLC),如第二张图片。
我已经分别完成了这些内容,现在我想把它们链接在一起
您在问题标题中询问关于从控制器调用文件后面代码中的方法,这很简单。由于文件后面的代码就是类,所以您可以像调用其他方法的类一样调用它们,就像这样
public ActionResult ShowForm()
{
MvcApplication1.Webforms.Reportform form = new Webforms.Reportform();
form.ShowForm();
}
但是我不认为你在寻找那个。正如你用图片解释的那样,你想在MVC中生成的"生成报告"视图上调用ASPX功能。你可以通过两种方式做到这一点,要么你收集所有必要的参数在客户端(javascript, jquery等),然后从那里直接重定向到你的aspx查询字符串,如
$("#generateReport").on('click', function() {
var category = $("#category").val();
//similarly do for all the fields
if (category!= undefined && category != null) {
window.location = '/Report.aspx?category=' + category;
}
});
在这种情况下,您还需要在Report中编写逻辑。从查询字符串中获取值,然后用适当的输入调用showreport方法
另一种方法是将GenerateReport发回MVC,收集参数,然后将其进一步发送到aspx,就像这样
[HttpPost]
public ActionResult GenerateReport(FormCollection collection)
{
try
{
string category = collection["category"];
// TODO: Add similar information for other fields
return Redirect(string.format("/Report.aspx?category={0}",category)); //add additional parameters as required
}
catch
{
return View();
}
}
与从客户端脚本直接调用相比,这将导致额外的返回旅程。