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

Asp.net templated razor delegates

on

  • 396 views

 

Statistics

Views

Total Views
396
Views on SlideShare
396
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Asp.net templated razor delegates Asp.net templated razor delegates Presentation Transcript

  • ASP.NET MVC Templated Razor Delegates Jason
  • Templated Razor Delegates Index.cshtml @{ Func<dynamic, object> strongTag = @<strong>@item</strong>; } <span>This sentence is @strongTag("Jason").</span>
  • @Helper Syntax Index.cshtml @helper Create(string name, int age) { <p> <span>@name</span> <span>@age</span> </p> } @Create("Jason", 18)
  • @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)
  • HelperResult Class Index.cshtml @{ var items = new[] { "one", "two", "three" }; } <ul> @items.List(@<li>@item</li>) <ul>
  • 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); } }); }
  • 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