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

时间:2018-08-15 01:29:44

标签: jquery asp.net-mvc

我想将单选按钮值发送到protected override void OnActionExecuted内部的控制器_Layout

有人可以建议我该怎么做吗?

_Layout

<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();

                }
            })

1 个答案:

答案 0 :(得分:0)

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