繁体   English   中英

有什么方法可以将值发送到MVC中受保护的重写void OnActionExecuted

[英]Are there any way to send value into protected override void OnActionExecuted in MVC

我想将单选按钮值发送到_Layoutprotected override void OnActionExecuted控制器protected override void OnActionExecuted

谁能建议我该怎么做?

_布局

<div class="NorthSouthHemisphere">
      @Html.RadioButton("NorthernSouthernHemisphere", "NH")Northern
      @Html.RadioButton("NorthernSouthernHemisphere", "SH")Southern
  </div>

调节器

protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (User != null)
            {
                var context = new ApplicationDbContext();
                var username = User.Identity.Name;

                if (!string.IsNullOrEmpty(username))
                {
                    var user = context.Users.SingleOrDefault(u => u.UserName == username);
                   var Account = context.Account.SingleOrDefault(u => u.AccountId == user.AccountID);
                    var Country = context.Country.SingleOrDefault(u => u.CountryId == user.CountryID);
                    string fullName = string.Concat(new string[] { user.FirstName, " ", user.LastName });

                }
            }
            Hemishpere();
            base.OnActionExecuted(filterContext);
        }

脚本

 $(document).on('change', '.NorthSouthHemisphere input[type = "radio"]', function () {
                 var selectedVal = "";
                var selected = $(".NorthSouthHemisphere input[type='radio']:checked");
                if (selected.length > 0) {
                    selectedVal = selected.val();

                }
            })

ActionExecutedContext类可以访问HttpContext的实例,因此,您必须采取的一种选择是在控制器中配置一个ActionResult该控制器负责设置要在OnActionExecuted内部访问的会话变量的值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM