This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credit: http://stackoverflow.com/a/2759898/487544 | |
public static string RenderRazorViewToString(this Controller controller, string viewName, object model) | |
{ | |
controller.ViewData.Model = model; | |
using (var sw = new StringWriter()) | |
{ | |
var viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName); | |
var viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, sw); | |
viewResult.View.Render(viewContext, sw); | |
viewResult.ViewEngine.ReleaseView(controller.ControllerContext, viewResult.View); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*-- js/nojs with Modernizr --*/ | |
html.js .js-hide, .no-js-hide | |
{ | |
display: none; | |
} | |
html.js .no-js-hide | |
{ | |
display: inherit; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*-- to detect mobile size in js --*/ | |
/* credit: http://bricss.net/post/22198838298/easily-checking-in-javascript-if-a-css-media-query-has */ | |
function isMobileSize() { | |
var size = window.getComputedStyle(document.body, ':after').getPropertyValue('content'); | |
return size.indexOf('mobile') != -1; | |
} | |
/* | |
@media (max-width: 767px) | |
{ | |
body:after |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credit: @mcintyre321 | |
public static class ModelStateDictionaryExtensions | |
{ | |
public static bool Try(this ModelStateDictionary ms, string key, Action action) | |
{ | |
try | |
{ | |
action(); | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// adds the active class if the link's action & controller matches current request | |
/// </summary> | |
public static MvcHtmlString MenuActionLink(this HtmlHelper htmlHelper, | |
string linkText, string actionName, string controllerName, | |
object routeValues = null, object htmlAttributes = null, | |
string activeClassName = "active") | |
{ | |
IDictionary<string, object> htmlAttributesDictionary = | |
HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string AbsoluteAction(this UrlHelper url, | |
string actionName, string controllerName, object routeValues = null, bool isHttps = false) | |
{ | |
return url.Action(actionName, controllerName, routeValues, "http" + (isHttps ? "s" : "")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string Truncate(this string s, int maxLength, bool withEllipsis = false) | |
{ | |
if (maxLength < 0) throw new ArgumentOutOfRangeException(nameof(maxLength), "must be at least zero"); | |
if (s == null || s.Length <= maxLength) return s; | |
if (withEllipsis && maxLength > 3) | |
{ | |
return s.Substring(0, maxLength - 3) + "..."; | |
} | |
return s.Substring(0, maxLength); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credit: http://www.extensionmethod.net/Details.aspx?ID=453 | |
public static string ToUrlFragment(this string s) | |
{ | |
if (String.IsNullOrEmpty(s)) return ""; | |
// Unicode Character Handling: http://blogs.msdn.com/b/michkap/archive/2007/05/14/2629747.aspx | |
string stFormD = s.Trim().ToLowerInvariant().Normalize(NormalizationForm.FormD); | |
var sb = new StringBuilder(); | |
foreach (var t in from t in stFormD let uc = CharUnicodeInfo.GetUnicodeCategory(t) where uc != UnicodeCategory.NonSpacingMark select t) | |
{ | |
sb.Append(t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Converts PascalCase and camelCase to underscore_case. Leaves underscore_case unaffected. | |
/// </summary> | |
/// <param name="s">the string to convert</param> | |
/// <returns>the underscore_cased string</returns> | |
internal static string ToUnderscoreCase(this string s) | |
{ | |
return Regex.Replace(s, @"(\p{Ll})(\p{Lu})", "$1_$2").ToLower(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use Microsoft.Experience.CloudFx.Framework.Storage.InMemoryCloudTableStorage |
OlderNewer