How to read WordPress feeds in a C# MVC .Net application

This is a very easy method you could use to read XML data from a feed and instantiate the object you need with that information. For the following example, I am using an MVC .Net Application code.

First you need to create the Model to store the posts information.

 public partial class BlogPost
    public string Name { get; set; }
    public string URL { get; set; }
    public string Description { get; set; }
    public System.DateTime Date { get; set; }

The following step is used to read the XML data, I have created a helper class with a static method.

public class BlogPostsLookUp
    public static IEnumerable<BlogPost> GetBlogPosts()
      XDocument feedXML = XDocument.Load("");

      var feeds = from feed in feedXML.Descendants("item")
            select new BlogPost
              Name = feed.Element("title").Value,
              URL = feed.Element("link").Value,
              Date = DateTime.Parse(feed.Element("pubDate").Value),
              Description = feed.Element("description").Value,

       return feeds;

Once you have the list of blog post you can use it in the View for displaying the information

<ol class="blog-home">
    @foreach (var blog in BlogPostsLookUp.GetBlogPosts())
           <a href="@blog.URL" target="_blank">@blog.Name <br /></a>
           <span style="color: #b8c4c4">
               posted on 
               <span style="color:#808080;font-style:italic">
                  @blog.Date.ToString("MMMM dd, yyyy")


How to find the properties responsible when an EntityValidationErrors occurs.

So I just upgraded my Entity Framework to version 6.0 and started getting the EntityValidationErrors . It turn outs I have been following a wrong pattern in creating views and models. I did not use the ViewModel concept and added extra fields to the normal model. So during the validations these extra fields keep causing the errors.

The error I keep getting was “Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details”, and does not give any details of the fields responsible for the error. The following code gives you the properties list that caused the error.

entityvalidations error

Static Content Caching with ASP.Net MVC

I have been researching ways to cache contents in a website that I am working on. Below details how you could cache static contents in a ASP.Net MVC project.

This method does caching for CSS, JavaScript and image files as well.

Here is what you need to do 

Include the below content in your root web.config file, section system.webServer. The below code caches content for 7 days. 

      <clientCache  cacheControlMode="UseMaxAge" 
cacheControlMaxAge="7.00:00:00" />

What is the difference between ViewData, ViewBag and TempData in MVC.Net?

The ViewData, ViewBag and TempData are the mechanism in Asp.Net MVC which allows data to be passed between controller, view or the next action. The ViewBag and ViewData have same usage and behave very similarly unlike the TempData which has its own functions. Below I have described how they are used in different context.


ViewData is a dictionary object which helps the data to be sent from the controller to the view. The data is accessible via a string key and sometimes it requires typecasting for complex data type.

public ActionResult Home()
ViewData["Title"] = "I am a software developer";
return View();

and in the view you can easily access the data.


ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0 and does not require type casting for complex objects.

public ActionResult Home()
ViewData.Title = "I am a software developer";
return View();

and in the view you can easily access the data.


TempData is also a dictionary object which is stored in session. The object is stored in session with a string key and value. This mechanism pass data from one controller to another and also between one action to another action.


public ActionResult Index()
TempData["Message"] = "I am a software developer";
return RedirectToAction("Home");

public ActionResult Home()
var message = TempData[“Message”];
ViewBag.Message = message;
return View();