Created
May 17, 2011 12:13
-
-
Save linuxbender/976361 to your computer and use it in GitHub Desktop.
MVC 3 - Razor - C# -Custom helper: @Html.Script
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>@ViewBag.Title</title> | |
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="page"> | |
<header> | |
<div id="title"> | |
<h1>Helper Demo</h1> | |
</div> | |
<div id="logindisplay"> </div> | |
<nav> | |
<ul id="menu"> | |
<li>@Html.ActionLink("Home", "Index", "Home")</li> | |
<li>@Html.ActionLink("About", "About", "Home")</li> | |
</ul> | |
</nav> | |
</header> | |
<section id="main"> | |
@RenderBody() | |
</section> | |
<footer> | |
@Html.Label(DateTime.Now.Year.ToString())©kinesys.ch | |
</footer> | |
</div> | |
@Html.Script("jquery-1.6.1.min.js") | |
</body> | |
</html> |
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
using System.Web.Mvc; | |
namespace Starwolf.ch.Helpers | |
{ | |
public static class MyHelpers | |
{ | |
public static MvcHtmlString Script(this HtmlHelper helper, string src) | |
{ | |
// <script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script> | |
var builder = new TagBuilder("script"); | |
builder.MergeAttribute("src", "/Scripts/" + src); | |
builder.MergeAttribute("type", "text/javascript"); | |
return MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal)); | |
} | |
}//end of class | |
}//end of namespace |
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
<add namespace="Starwolf.ch.Helpers" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment