MVC 3 MvcExtensions should return MvcHtmlString

Nov 26, 2010 at 8:33 PM

Combres.Mvc.MvcExtensions methods should return MvcHtmlString instead of string.

The importance of this is that when using Html helpers in a razor cshtml file;

@Html.CombresLink("myresourceSet")

We end up with the string HtmlEncoded since Razor encodes everything by default.
So we see the link on the page instead of the resource being pulled from the server.

Temporary down and dirty work around by creating your own extension method;

	public static MvcHtmlString CombresMvcLink(this HtmlHelper helper, string resourceSet)
         {
            return MvcHtmlString.Create(Combres.WebExtensions.CombresLink(resourceSet));
         }
Thoughts?
RA
Nov 26, 2010 at 8:41 PM
    /// <summary>
    /// Utility class providing extension methods for ASP.NET MVC applications to
    /// work with the library.
    /// </summary>
    public static class MvcExtensions
    {
        /// <summary>
        /// Forwards the call to <see cref="WebExtensions.CombresUrl"/> and <see cref="MvcHtmlString"/> Create method.
        /// </summary>
        public static MvcHtmlString CombresUrl(this HtmlHelper html, string setName)
        {
            return MvcHtmlString.Create( WebExtensions.CombresUrl(setName));
        }

        /// <summary>
        /// Forwards the call to <see cref="WebExtensions.CombresUrl"/> and <see cref="MvcHtmlString"/> Create method.
        /// </summary>
        public static MvcHtmlString CombresUrl(this UrlHelper url, string setName)
        {
            return MvcHtmlString.Create(WebExtensions.CombresUrl(setName));
        }

        /// <summary>
        /// Forwards the call to <see cref="WebExtensions.CombresLink(string)"/> and <see cref="MvcHtmlString"/> Create method.
        /// </summary>
        public static MvcHtmlString CombresLink(this HtmlHelper html, string setName)
        {
            return MvcHtmlString.Create(WebExtensions.CombresLink(setName));
        }

        /// <summary>
        /// Forwards the call to <see cref="WebExtensions.CombresLink(string, object)"/> and <see cref="MvcHtmlString"/> Create method.
        /// </summary>
        public static MvcHtmlString CombresLink(this HtmlHelper html, string setName, object htmlAttributes)
        {
            return MvcHtmlString.Create(WebExtensions.CombresLink(setName, htmlAttributes));
        }

        /// <summary>
        /// Forwards the call to <see cref="WebExtensions.CombresLink(string)"/> and <see cref="MvcHtmlString"/> Create method.
        /// </summary>
        public static MvcHtmlString CombresLink(this UrlHelper url, string setName)
        {
            return MvcHtmlString.Create(WebExtensions.CombresLink(setName));
        }

        /// <summary>
        /// Forwards the call to <see cref="WebExtensions.CombresLink(string, object)"/> and <see cref="MvcHtmlString"/> Create method.
        /// </summary>
        public static MvcHtmlString CombresLink(this UrlHelper url, string setName, object htmlAttributes)
        {
            return MvcHtmlString.Create(WebExtensions.CombresLink(setName, htmlAttributes));
        }
    }
Nov 30, 2010 at 8:28 AM

Thanks for the suggestion, Ryan.  The change is updated to the latest Combres' code.