title: Base Controller Get Value
body: <p>I having trouble getting a value to my base controller. All I would like to do is have my base controller pick up an ID from an ActionLink?</p>
  <p><strong>Link</strong></p>
  <pre><code>&lt;%= Html.ActionLink(&quot;About Us&quot;, &quot;About&quot;, new { SectionId = 1 })%&gt;
  </code></pre>
  <p><strong>Base Controller</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  
  namespace Website.Controllers
  {
      public class SectionController : Controller
      {
          //
          // GET: /Section/
  
          public SectionController(int SectionId)
          {
              if (SectionId == 1)
              {
                  ViewData[&quot;Message&quot;] = &quot;GOT AN ID&quot;;
              }
              else
              {
                  ViewData[&quot;Message&quot;] = &quot;NO ID&quot;;
              }
          }
      }
  }
  </code></pre>
  <p><strong>Home Controller</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  
  namespace Website.Controllers
  {
      [HandleError]
      public class HomeController : SectionController
      {
          public ActionResult Index()
          {
              return View();
          }
  
          public ActionResult About()
          {
              return View();
          }
  
  
          public ActionResult Contact()
          {
              return View();
          }
  
     }
  }
  </code></pre>
  <p><strong>Solution so far</strong></p>
  <p><strong>ActionLink</strong></p>
  <pre><code>&lt;%= Html.ActionLink(&quot;About Us&quot;, &quot;About&quot;, new { SectionId = 1})%&gt;
  </code></pre>
  <p><strong>SectionAttribute.cs</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  
  namespace Website.ActionFilters
  {
      public class SectionAttribute : ActionFilterAttribute
      {
          public override void OnActionExecuting(ActionExecutingContext filterContext)
          {
          // Actions have sectionId parameter
          object SectionId = filterContext.ActionParameters.FirstOrDefault(x =&gt; x.Key == &quot;SectionId&quot;).Value;
  
              if (SectionId != null &amp;&amp; (int)SectionId == 1)
              {
                  filterContext.Controller.ViewData[&quot;Message&quot;] = &quot;GOT AN ID&quot;;
              }
              else
              {
                  filterContext.Controller.ViewData[&quot;Message&quot;] = &quot;NO ID&quot;;
              }
          }
      }
  }
  </code></pre>
  <p><strong>SectionController</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using Website.ActionFilters;
  
  namespace Website.Controllers
  {
      [Section]
      public class SectionController : Controller
      {
      }
  }
  </code></pre>
  <p><strong>View</strong></p>
  <pre><code>&lt;%= Html.Encode(ViewData[&quot;Message&quot;]) %&gt;
  </code></pre>