Asp.net templated razor delegates
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
492
On Slideshare
492
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. ASP.NET MVC Templated Razor Delegates Jason
  • 2. Templated Razor Delegates Index.cshtml @{ Func<dynamic, object> strongTag = @<strong>@item</strong>; } <span>This sentence is @strongTag("Jason").</span>
  • 3. @Helper Syntax Index.cshtml @helper Create(string name, int age) { <p> <span>@name</span> <span>@age</span> </p> } @Create("Jason", 18)
  • 4. @Helper Syntax Person.cshtml in App_Code Folder @helper Create(string name, int age) { <p> <span>@name</span> <span>@age</span> </p> } Index.cshmtl @Person.Create("Jason", 18)
  • 5. HelperResult Class Index.cshtml @{ var items = new[] { "one", "two", "three" }; } <ul> @items.List(@<li>@item</li>) <ul>
  • 6. HelperResult Class RazorExtensions.cs public static HelperResult List<T>(this IEnumerable<T> items, Func<T, HelperResult> template) { return new HelperResult(writer => { foreach (var item in items) { template(item).WriteTo(writer); } }); }
  • 7. Reference  Templated Razor Delegates  http://haacked.com/archive/2011/02/27/templated-razor- delegates.aspx  Helper syntax within Razor  http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3- and-the-helper-syntax-within-razor.aspx  MSDN-HelperResult  http://msdn.microsoft.com/zh- tw/library/system.web.webpages.helperresult(v=vs.111).aspx