title: itunes rss with c# MVC
body: <p>Hello all I am trying to create a live updated RSS feed for itunes using asp.net MVC.  I can't seem to get the feed to validate and when you navigate to the page the xml is not formatted like it is when I made one with a webforms.</p>
  
  <p>This is the View</p>
  
  <pre><code>            @model IEnumerable&lt;lofbc.org.Models.media&gt;
  
              @{
                  Layout = null;
              }
  
              &lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  
              &lt;rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" version="2.0"&gt;
  
                  &lt;channel&gt;
                      &lt;title&gt;Life of Faith Bible Church Podcast&lt;/title&gt;
                      &lt;link&gt;@Request.Url.Host&lt;/link&gt;
                      &lt;description&gt;Welcome to Life of Faith Bible Church! We are dedicated to bringing you life-changing resources through our podcast and audio messages. You will find a wealth of material that will help you triumph in every area of life.&lt;/description&gt;
                      &lt;language&gt;en-us&lt;/language&gt;
                      &lt;copyright&gt;New Life Media copyright @DateTime.Now.Year&lt;/copyright&gt;
                      &lt;atom:link href="https://www.lofbc.org/rss" rel="self" type="application/rss+xml" /&gt;
  
                      &lt;!--itunes specific--&gt;
                      &lt;itunes:author&gt;Life of Faith Bible Church&lt;/itunes:author&gt;
                      &lt;itunes:summary&gt;Welcome to Life of Faith Bible Church! We are dedicated to bringing you life-changing resources through our podcast and audio messages. You will find a wealth of material that will help you triumph in every area of life.&lt;/itunes:summary&gt;
                      &lt;itunes:owner&gt;
                          &lt;itunes:name&gt;Life of Faith Bible Church&lt;/itunes:name&gt;
                          &lt;itunes:email&gt;justin@lofbc.org&lt;/itunes:email&gt;
                      &lt;/itunes:owner&gt;
                      &lt;itunes:explicit&gt;No&lt;/itunes:explicit&gt;
                      &lt;itunes:image href="http://www.lofbc.org/rss/artwork/artwork.jpg" /&gt;
                      &lt;itunes:category text="Religion &amp; Spirituality"&gt; &lt;/itunes:category&gt;
  
                      @foreach (var item in Model)
                          {
                              var date = item.createdDate.ToString("yyyy");
                              var path = item.audioPath.ToString().Replace(".f4v", ".mp3");
  
                          &lt;item&gt;
                              &lt;title&gt;@item.title&lt;/title&gt;
                              &lt;url&gt;http://lofbc-media.s3.amazonaws.com/@date/Audio/mp3/@path&lt;/url&gt;
                              &lt;pubDate&gt;@item.createdDate.ToString("MMM dd, yyyy")&lt;/pubDate&gt;
                              &lt;description&gt;@item.description&lt;/description&gt;
                              &lt;enclosure url="http://lofbc-media.s3.amazonaws.com/@item.createdDate.ToString("yyyy"))/Audio/mp3/@item.audioPath.ToString().Replace(".f4v", ".mp3")" length=""  type="audio/mpeg" /&gt;
  
  
                              &lt;itunes:summary&gt;@item.description&lt;/itunes:summary&gt;
                          &lt;/item&gt;
                      }
                  &lt;/channel&gt;
              &lt;/rss&gt;
  </code></pre>
  
  <p>and this is the controller </p>
  
  <pre><code>            using lofbc.org.context;
              using lofbc.org.Models;
              using System;
              using System.Collections.Generic;
              using System.Data.SqlClient;
              using System.Linq;
              using System.Web;
              using System.Web.Mvc;
  
              namespace lofbc.org.Controllers
              {
                  public class rssController : Controller
                  {
                      // GET: rss
                      public ActionResult Index()
                      {
                          using (ServiceArchivesEntities db = new ServiceArchivesEntities())
                          {
                              try
                              {
                                  DateTime startDate = DateTime.Parse("01/01/2015 00:00:00");
  
                                  var MT = (from a in db.tbl_media
                                            join b in db.tbl_media_ministers
                                            on a.MinisterID equals b.ID
                                            select new media
                                            {
                                                id = a.ID,
                                                createdDate = (DateTime)a.CreatedDate,
                                                title = a.Title,
                                                minister = b.Title + " " + b.FirstName + " " + b.LastName,
                                                audioPath = a.PathToAudio,
                                                videoPath = a.PathToVideo,
                                                views = a.Views,
                                                listens = a.Listens,
                                                status = a.Status
                                            }).Where(t =&gt; t.status == 2 &amp;&amp; t.createdDate &gt;= startDate).OrderByDescending(t =&gt; t.createdDate).Take(100).ToList();
  
                                  return View(MT);
                              }
                              catch (SqlException ex)
                              {
                                  Response.Write(ex.ToString());
                                  return View();
                              }
  
                          }
                      }
                  }
              }
  </code></pre>
  
  <p>Live demo <a href="http://development.lofbc.org/rss" rel="nofollow noreferrer">http://development.lofbc.org/rss</a></p>