title: Generate Page Title and Meta Tags from database using URL path
body: <p>I want to dynamically change the title tag by getting the name from the database. This internal database already has the name and ID in the same table but I'm having trouble.</p>
  <p>What I wish to do is get the QRLinkCode from the Url Path and then return the Name associated with that QRLinkCode to populate the title meta tag in the view source.</p>
  <p>This is what I have written so far.</p>
  <pre><code>     public class PageMetaDetails
              {
                  public static string UpdateMetaDetails (string urlpath)
                  {
                      //--- StringBuilder object to store MetaTags information.
                      StringBuilder sbMetaTags = new StringBuilder();
          
                      //--Step1 Get data from database.
          
                      using (TemplateDBEntities db = new TemplateDBEntities())
                      {
                         
                          var qrLinkName = &quot;&quot;;
                          
                          
                           if (urlpath.StartsWith(&quot;/ItemList&quot;))
                          {
                              //get qrLink code out of the url
                              var qrLinkId = urlpath.Substring(urlpath.Length - 6);
          
          
                              //hit the database for this qr link by id
                              var qrLink = db.QRLinks.FirstOrDefault(x =&gt; x.QRLinkCode == qrLinkId);
                              qrLinkName = qrLink.Name;
                              
                              
          
                          }
                          
          
                          //---- Step2 In this step we will add &lt;title&gt; tag to our StringBuilder Object.
                          //sbMetaTags.Append(qrLinkName);
                          //sbMetaTags.Append(Environment.NewLine);
          
                          
                          return qrLinkName;
                      }
          
                      
                  }
                  
                 
              } 
  </code></pre>
  <blockquote>
  <p>There is code that will go in between this that's why its not there
  are extra {} but I just want to get this part working first.</p>
  </blockquote>
  <p>I also have this below in the Layout.cshtml to route the name to the title meta tag.</p>
  <pre><code>&lt;title&gt;
          @{string title = Url.RequestContext.RouteData.Values[&quot;controller&quot;] + &quot;/&quot; + Url.RequestContext.RouteData.Values[&quot;action&quot;];
              @(Html.Raw(Models.PageMetaDetails.UpdateMetaDetails(title)));} &lt;/title&gt;
  </code></pre>
  <p>For some reason its not returning the name associated with the ID. If anyone has any idea let me know where I'm going wrong.</p>