{"id":16411751,"url":"https://github.com/c0shea/webhelpers.mvc5","last_synced_at":"2025-06-16T04:04:45.845Z","repository":{"id":23099980,"uuid":"98124102","full_name":"c0shea/WebHelpers.Mvc5","owner":"c0shea","description":"Helpers for ASP.NET MVC5","archived":false,"fork":false,"pushed_at":"2022-12-08T01:20:45.000Z","size":1288,"stargazers_count":9,"open_issues_count":6,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T21:19:16.663Z","etag":null,"topics":["asp-net-mvc5","csharp"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c0shea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-23T20:41:03.000Z","updated_at":"2024-03-12T12:42:08.000Z","dependencies_parsed_at":"2023-01-13T22:45:17.169Z","dependency_job_id":null,"html_url":"https://github.com/c0shea/WebHelpers.Mvc5","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0shea%2FWebHelpers.Mvc5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0shea%2FWebHelpers.Mvc5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0shea%2FWebHelpers.Mvc5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c0shea%2FWebHelpers.Mvc5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c0shea","download_url":"https://codeload.github.com/c0shea/WebHelpers.Mvc5/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245066496,"owners_count":20555402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-mvc5","csharp"],"created_at":"2024-10-11T06:46:28.353Z","updated_at":"2025-03-23T06:31:07.645Z","avatar_url":"https://github.com/c0shea.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebHelpers.Mvc5\n\n![Build Status](https://coshea.visualstudio.com/_apis/public/build/definitions/c4f53986-29b5-45cd-b130-b074bbc802b0/4/badge)\n![NuGet](https://img.shields.io/nuget/v/WebHelpers.Mvc5.svg)\n\nA collection of helpers for ASP.NET MVC5.\n\n## CssRewriteUrlTransformAbsolute\n\nConverts any URLs in the input to absolute using the application's base directory.\nThe standard `CssRewriteUrlTransform` class doesn't use the application's absolute path required\nby many assets.\n\nFor example, `url(../fonts/glyphicons.woff)` is rewritten as\n`url(Contoso/Content/fonts/glyphicons.woff)` for an application whose base directory is Contoso.\n\n```cs\n.Include(\"~/Content/css/bootstrap.min.css\", new CssRewriteUrlTransformAbsolute())\n```\n\n## IsLinkActive\n\nWhen building static navigation, there are two approaches to highlight the link of the current page\nas active. Either you can run some JavaScript to sniff out the URLs or you can build out an `if` statement\nfor every link to determine whether or not to apply the class.\n\nTo make the second option easier, you can turn this:\n\n```cshtml\n\u003cli class=\"@(ViewContext.RouteData.Values[\"Action\"].ToString() == nameof(HomeController.Index) ? \"active\" : \"\")\"\u003e\n    \u003ca href=\"@Url.Action(\"Index\", \"Home\")\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e \u003cspan\u003eHome\u003c/span\u003e\u003c/a\u003e\n\u003c/li\u003e\n```\n\ninto this:\n\n```cshtml\n\u003cli class=\"@Url.IsLinkActive(\"Index\", \"Home\")\"\u003e\n    \u003ca href=\"@Url.Action(\"Index\", \"Home\")\"\u003e\u003ci class=\"fa fa-link\"\u003e\u003c/i\u003e \u003cspan\u003eHome\u003c/span\u003e\u003c/a\u003e\n\u003c/li\u003e\n```\n\n## IsTreeviewActive\n\nSimilar to `IsLinkActive`, this makes it easy to determine whether the treeview is the active link.\n\n```\n@{\n    var treeviewActions = new Dictionary\u003cstring, string\u003e\n    {\n        { \"Action\", \"Controller\" }\n    };\n}\n\n\u003cli class=\"treeview @Url.IsTreeviewActive(treeviewActions)\"\u003e\n    \u003ca href=\"#\"\u003e\u003ci class=\"fa fa-cogs\"\u003e\u003c/i\u003e \u003cspan\u003eAction\u003c/span\u003e \u003ci class=\"fa fa-angle-left pull-right\"\u003e\u003c/i\u003e\u003c/a\u003e\n    \u003cul class=\"treeview-menu\"\u003e\n        \u003cli class=\"@Url.IsLinkActive(\"Action\", \"Controller\")\"\u003e\n            \u003ca href=\"@Url.Action(\"Action\", \"Controller\")\"\u003e\u003ci class=\"fa fa-trash\"\u003e\u003c/i\u003e \u003cspan\u003eAction\u003c/span\u003e\u003c/a\u003e\n        \u003c/li\u003e\n    \u003c/ul\u003e\n\u003c/li\u003e\n```\n\n## AddVersion\n\nAdds a cache-busting version number, which is the number of ticks since the last write time of the file,\nas a query parameter to the URL of the asset.\n\n```cshtml\n\u003cimg src=\"@Url.Content(\"~/Content/img/user.png\").AddVersion()\" /\u003e\n```\n\noutputs\n\n```\n/Content/img/user.png?v=636296810982047488\n```\n\n## EnumHandler\n\nRenders Enums as a frozen object in JavaScript to promote re-usability between the server and client.\n\nAdd to your Web.config:\n\n```\n\u003csystem.webServer\u003e\n    \u003chandlers\u003e\n        \u003cremove name=\"WebHelpers\" /\u003e\n        \u003cadd name=\"WebHelpers\" verb=\"GET\" path=\"WebHelpers.axd\" type=\"WebHelpers.Mvc5.Enum.EnumHandler\" preCondition=\"integratedMode\" /\u003e\n    \u003c/handlers\u003e\n\u003c/system.webServer\u003e\n```\n\nAdd to your _Layout.cshtml:\n\n```\n\u003cscript src=\"@EnumHandler.HandlerUrl\"\u003e\u003c/script\u003e\n```\n\nThen decorate your enum with the `ExposeInJavaScript` attribute:\n```\n[ExposeInJavaScript]\npublic enum MyEnum\n{\n    Test\n}\n```\n\nAlternatively, you can specify the enums to include and exclude via configuration.\nThis is helpful if you choose to keep your enums clean or if they reside in other\nlibraries that can't take on this dependency. To do this, you can register them in\nyour `Global.asax`.\n\n```\nprotected void Application_Start()\n{\n    EnumHandler.EnumsToExpose.Include(typeof(MyEnum));\n}\n```\n\n## ClientIP\n\nGets the IP address of the client sending the request. This method will return the originating\nIP if specified by a proxy but makes no guarantee that this is the client's true IP address.\nSince these headers can be spoofed, you are encouraged to perform additional validation if\nyou are using the IP in a sensitive context.\n\n```\nvar ip = HttpContext.Current.Request.ClientIP();\n```\n\n## jqGrid\n\n### License\n\njqGrid is not licensed under the MIT license like this project. See [here](http://guriddo.net/?page_id=103334)\nfor its license. It is only included in the Demo project for the purposes of demonstration\nin a non-commercial capacity.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc0shea%2Fwebhelpers.mvc5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc0shea%2Fwebhelpers.mvc5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc0shea%2Fwebhelpers.mvc5/lists"}