在 C#.NET MVC 模式中订阅事件
Subscribing to Events in C#.NET MVC pattern
我在我的项目中使用 DevExpress
仪表板 MVC Control
。
我需要从服务器 side.Currently 订阅控件支持的一些事件 我正在 MVC Controller
.
订阅它们
这是我放置 Event Handling
代码的最佳位置吗?是否需要取消订阅这些事件以避免内存泄漏?
public class HomeController : Controller
{
public ActionResult Index(string mode)
{
//Some code commented
DashboardConfigurator.Default.CustomFilterExpression += MvcDashboard_CustomFilterExpression;
DashboardConfigurator.Default.CustomParameters += (sender, eventArgs) =>{
//Event specific code
};
return View();
}
public void MvcDashboard_CustomFilterExpression(object sender, CustomFilterExpressionWebEventArgs e)
{
// Event specific code
}
}
DevExpress建议在Global.asax.cs
中的Application_Start方法中定义
We suggest specifying the default controller's settings in the Application_Start method in the Global.asax.cs file or in the RegisterService method in the DashboardConfig.cs file. The code snippet in the Step 9. Create a Dashboard Storage section of the Create an ASP.NET MVC Dashboard Application topic demonstrates this approach.
我在我的项目中使用 DevExpress
仪表板 MVC Control
。
我需要从服务器 side.Currently 订阅控件支持的一些事件 我正在 MVC Controller
.
这是我放置 Event Handling
代码的最佳位置吗?是否需要取消订阅这些事件以避免内存泄漏?
public class HomeController : Controller
{
public ActionResult Index(string mode)
{
//Some code commented
DashboardConfigurator.Default.CustomFilterExpression += MvcDashboard_CustomFilterExpression;
DashboardConfigurator.Default.CustomParameters += (sender, eventArgs) =>{
//Event specific code
};
return View();
}
public void MvcDashboard_CustomFilterExpression(object sender, CustomFilterExpressionWebEventArgs e)
{
// Event specific code
}
}
DevExpress建议在Global.asax.cs
中的Application_Start方法中定义We suggest specifying the default controller's settings in the Application_Start method in the Global.asax.cs file or in the RegisterService method in the DashboardConfig.cs file. The code snippet in the Step 9. Create a Dashboard Storage section of the Create an ASP.NET MVC Dashboard Application topic demonstrates this approach.