Click here to Skip to main content
15,893,487 members
Articles / Web Development / XHTML

ASP.NET MVC Calendar by extending the HtmlHelper

Rate me:
Please Sign up or sign in to vote.
2.71/5 (5 votes)
24 Jul 2008CPOL2 min read 107.4K   2.1K   23  
You need a Calendar to show months or archive data or others, then you'd like this.
<%@ Page Title="Archived Posts" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Archive.aspx.cs" Inherits="MvcCalendarSample.Views.Home.Archive" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<h2>Mvc Calendar 4: with data and links and selected date</h2>
<%
    var selectedDate = DateTime.Parse(ViewData["date"].ToString());
    var allPosts = MvcCalendarSample.Models.Post.GetAllPosts();
    var datesArray = from d in allPosts
                     select new DateTime(d.CreatedAt.Ticks);
%>

<%= Html.Calendar("archiveCalendar", selectedDate, datesArray, "home", "archive") %>

<hr />

<h2>Archived posts in <%= ViewData["date"] %></h2>
<%
    var selectedPosts = ViewData["posts"] as List<MvcCalendarSample.Models.Post>;
%>
<p>Total <%= selectedPosts.Count%> posts in <%= ViewData["date"] %></p>

<% foreach (var post in selectedPosts)
   { %>
<p>[<%= post.CreatedAt %>] <a href="#"><%= post.Title %></a></p>
<%} %>
</asp:Content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions