Thank you for your help.
ASP.NET MVC has multiple controllers that inherit a common basic class, all configured with the same ActionFilter.
public class BaseController:controller
{
public MemberParam mParam;
}
AnalysisSession
public class memberController:BaseController
{
// some codes
}
AnalysisSession
public class HomeController:BaseController
{
// some codes
}
Inside the AnalysisSession action filter, I would like to set a value for the internal properties of the called controller.
public class AnalysisSessionAttribute:ActionFilterAttribute
{
public override void OnActionExecuting (ActionExecutingContext context) {
var sessions = context.HttpContext.Session;
// Get session(s) and get(s)
// a part of something that is not understood here
var controller=context.Controller as MemberController;
controller.mParam = this.mParam;
}
}
With a single controller, as you can see, it's a problematic reference, but with multiple controller/many properties, please tell me how to implement it simply.
c# asp.net
Based on the above comments, I will reply as self-responsive.
public class AnalysisSessionAttribute:ActionFilterAttribute
{
public override void OnActionExecuting (ActionExecutingContext context) {
var sessions = context.HttpContext.Session;
// Get session(s) and get(s)
// use a polymorphism to cast into the inheritance class
var controller=context.Controller as BaseController;
controller.mParam = this.mParam;
}
© 2024 OneMinuteCode. All rights reserved.