Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could write a custom helper to handle links that have dates:</p> <pre><code>namespace System.Web.Mvc { public static class LinkExtensions { public static MvcHtmlString DateLink(this HtmlHelper htmlHelper, string linkText, string actionName) { return DateLink(htmlHelper, linkText, actionName, new RouteValueDictionary(), null); } public static MvcHtmlString DateLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues) { return DateLink(htmlHelper, linkText, actionName, new RouteValueDictionary(routeValues), new RouteValueDictionary()); } public static MvcHtmlString DateLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes) { return DateLink(htmlHelper, linkText, actionName, new RouteValueDictionary(routeValues), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } public static MvcHtmlString DateLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues) { return DateLink(htmlHelper, linkText, actionName, routeValues, new RouteValueDictionary()); } public static MvcHtmlString DateLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues, IDictionary&lt;string, object&gt; htmlAttributes) { if (String.IsNullOrEmpty(linkText)) { throw new ArgumentException("linkText"); } //check additional parameters List&lt;string&gt; keys = new List&lt;string&gt;(routeValues.Keys); foreach (string key in keys) { if (routeValues[key].GetType() == typeof(DateTime)) routeValues[key] = ((DateTime)routeValues[key]).ToString("yyyy-MM-dd"); } return MvcHtmlString.Create(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, null, actionName, (string)routeValues["controller"], routeValues, htmlAttributes)); } } </code></pre> <p>And then you could use it like so:</p> <pre><code>@Html.DateLink("TestLink", "Details", new { starttime = new DateTime(2011, 1, 1), endtime = new DateTime(2012, 1, 1)}) </code></pre> <p>Which produces the following URL:</p> <pre><code>http://localhost/MyController/Details/2011-01-01/2012-01-01 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload