Allows you to write methods that contain mixed HTML and C# in Razor Views (.cshtml) / Razor Components (.razor) files.
This is a primitive for composing Razor code that is very low overhead / low concept. Your code calls your code.
In Views (not components): Can be async, can use tag helpers. In Components (not views): Usage and semantics still need figuring out, but we want to build something like this.
<h1>Here is some info about people on the team</h1>
@foreach(var person in people)
{
DisplayPerson(person);
}
@functions {
void DisplayPerson(Person person)
{
@<div>
<h3>
@person.Name is @person.Age
</h3>
@if (DateTime.Now.DayOfYear == person.Birthday.DayOfYear)
{
<h4>Happy Birthday! @person.Name</h4>
}
</div>
}
Person[] people = new Person[]
{
new Person()
{
Name = "Ryan",
Age = 33,
Birthday = new DateTime(1985, 9, 9),
},
new Person()
{
Name = "Dan", // Not Dan Roth, some other guy.
Age = 53,
Birthday = new DateTime(1965, 2, 3),
},
};
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public DateTime BirthDay { get; set; }
}
}
Is this W A V Y ? SPICY? Have you had cases where you wanted this? What would you add/change/remove?
Happy birthday! Text needs to be person.name not person.birthday