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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Asp.net templated razor delegates

427
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
427
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
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

×