@using MvcSample.Web.Models @model User @{ Layout = "/Views/Shared/_Layout.cshtml"; ViewBag.Title = "Home Page"; string nullValue = null; ViewBag.Anon = new { Name = "FirstName LastName", Address = new { Street = "123 Fake St.", City = "Redmond", State = "WA", Country = "USA", }, }; } @section header { } @section footer { } @functions { public async Task AsyncValueRetrieval() { return "Hello World"; } public Task RenderHelloWorldPartial(User model) { // Imagine this method was a super complex method that was used as a helper method. return Html.RenderPartialAsync("HelloWorldPartial", model); } }

ASP.NET

ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.

Learn more »

Hello @Model.Name! Happy @Model.Age birthday.

This value was retrieved asynchronously: @(await AsyncValueRetrieval())

Partial Async: @await Html.PartialAsync("HelloWorldPartial", Model)

Render Partial Async (Custom model): @{ await RenderHelloWorldPartial(new User() { Name="Bob" }); }

Book a flight

Go to our cool travel reservation system.

Reserve Now

Get more libraries

NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

Learn more »

Web Hosting

You can easily find a web hosting company that offers the right mix of features and price for your applications.

Learn more »

'@Html.NameForModel()' '@Html.ValueForModel()'
'@Html.Name("Name")' '@Html.Value("Name")'
'@Html.NameFor(m => m.Address)' '@Html.ValueFor(m => m.Address)'
'@Html.Name("Anon.Address.Street")' '@Html.Value("Anon.Address.Street")'
@await Component.InvokeAsync("Tags", 15)
@using (Html.BeginForm(controllerName: "Home", actionName: "Hello", method: FormMethod.Post)) {
@Html.TextBox("Name")
@Html.TextBoxFor(m => m.Address, htmlAttributes: new { @class = "form-control" })
} @{ Html.BeginForm(method: FormMethod.Post, htmlAttributes: new { someAttribute = "some value", }); }
@Html.TextBox("Anon.Name")
@Html.TextBox("Anon.Address.Street", (object)ViewBag.Anon.Address.Street)
@Html.TextBox("Anon.Address.City", value: null, format: "{0} (3)")
@Html.TextBox("Anon.Address.State", value: null, htmlAttributes: new { @class = "form-control" })
@Html.TextBox("Anon.Address.Country", value: null, format: "{0} (4)", htmlAttributes: new { @class = "form-control" })
@{ Html.EndForm(); }
'@Html.Display("Name")'
'@Html.Display("Dependent.Name")'
'@Html.Display("Alive")'
'@Html.Display("Dependent.Alive")'
'@Html.Display("Age")'
'@Html.Display("GPA")'
'@Html.DisplayFor(model => model.Name)'
'@Html.DisplayFor(model => model.Dependent.Name)'
'@Html.DisplayFor(model => model.Alive)'
'@Html.DisplayFor(model => model.Dependent.Alive)'
'@Html.DisplayFor(model => model.Age)'
'@Html.DisplayFor(model => model.GPA)'
@Html.DisplayForModel()