0% found this document useful (0 votes)
16 views2 pages

Core Done Example

The document provides an example of an ASP.NET Core MVC application that includes a model, controller, and view for a privacy form. The model 'form' contains validation attributes for first and last names, while the 'HomeController' handles form submission and validation. The view 'Privacy.cshtml' renders the form and displays validation messages using HtmlHelper methods.

Uploaded by

shakyalis222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Core Done Example

The document provides an example of an ASP.NET Core MVC application that includes a model, controller, and view for a privacy form. The model 'form' contains validation attributes for first and last names, while the 'HomeController' handles form submission and validation. The view 'Privacy.cshtml' renders the form and displays validation messages using HtmlHelper methods.

Uploaded by

shakyalis222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ASP.

NET Core MVC – HtmlHelper Form


Example
1 Model: [Link]
1️⃣

using [Link];

namespace [Link]
{
public class form
{
[Required(ErrorMessage = "First Name is required")]
public string FirstName { get; set; }

[Required(ErrorMessage = "Last Name is required")]


public string LastName { get; set; }
}
}

2️⃣Controller: [Link]

using [Link];
using [Link];

namespace [Link]
{
public class HomeController : Controller
{
public IActionResult Privacy()
{
return View();
}

[HttpPost]
public IActionResult Privacy(form form)
{
if ([Link])
{
return Content("Done");
}
else
{
return View(form);
}
}
}
}

3️⃣View: [Link]

@model [Link]

<h1>Privacy Form</h1>

@using ([Link]("Privacy", "Home", [Link]))


{
<div>
@[Link](m => [Link])
@[Link](m => [Link])
@[Link](m => [Link])
</div>

<div>
@[Link](m => [Link])
@[Link](m => [Link])
@[Link](m => [Link])
</div>

<button type="submit">Submit</button>
}

You might also like