public IActionResult Index()
{
List<Students> students = new List<Students>();
students.Add(new Students { Id=1,Name="Ram",City="Pune"});
students.Add(new Students { Id=2,Name="Shree",City="Mumbai"});
students.Add(new Students { Id=2,Name="Subhash",City="Kolkata"});
students.Add(new Students { Id=3,Name="Narendra",City="Chennai"});
return View(students);
}
@model List<Students>
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<h2>Value from Controller</h2>
@foreach (var student in Model)
{
<h2>@student.Name</h2>
<h3>@student.Id</h3>
<h3>@student.City</h3>
<hr />
}
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
Right click on "Contollers" folder -> Add -> Controller -> MVC Contoller - Empty -> Enter Name ->Add
using Microsoft.AspNetCore.Mvc;
namespace Test.Web.Controllers
{
public class AboutController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult History()
{
return View();
}
}
}
Right click on Method Name -> Add View -> Razor View
@{
ViewData["Title"] = "About Company";
}
<div class="container">
<h1>About Company</h1>
<div class="row">
<div class="col-12">
<p>At [Company Name], we are dedicated to revolutionizing the way [industry/niche] operates. Established in [year], we have been at the forefront of innovation, consistently delivering cutting-edge solutions to meet the evolving needs of our clients.</p>
<p>Our mission is simple: to empower businesses with the tools and technologies they need to thrive in today's competitive landscape. Whether you're a small startup or a multinational corporation, we tailor our services to suit your unique requirements, ensuring maximum efficiency and profitability.</p>
<a asp-action="History" class="btn btn-primary">Company History</a>
</div>
</div>
</div>
@{
ViewData["Title"] = "Company History";
}
<h1>Company History</h1>
<div class="container">
<div class="row">
<div class="col-12">
<p>
Since our inception in [year], [Company Name] has been synonymous with innovation and excellence in the [industry/niche] sector. What began as a humble startup with a vision to disrupt the status quo has evolved into a leading force in the industry, shaping the way businesses operate and thrive in the modern world.
</p>
<p>In our early days, [Founder's Name], our visionary founder, recognized a gap in the market and seized the opportunity to fill it. Armed with determination and a relentless pursuit of excellence, [Founder's Name] laid the foundation for what would become [Company Name]'s legacy of innovation.</p>
<a asp-action="Index" class="btn btn-primary">Back</a>
</div>
</div>
</div>
Entity Framework Core (EF Core) is a powerful and versatile object-relational mapping (ORM) framework developed by Microsoft. It is designed to simplify the process of working with relational databases in .NET applications by providing a high-level abstraction over the underlying database schema.
Method | Description |
---|---|
Add |
Adds a new entity to the context. |
Remove |
Removes an entity from the context. |
Update |
Updates the properties of an existing entity in the context. |
SaveChanges |
Saves all changes made in the context to the underlying database. |
Find |
Finds an entity with the given primary key values. |
FirstOrDefault /SingleOrDefault /First /Single |
Executes a query and returns the first matching entity or null if no matching entity is found. |
ToList /ToListAsync /ToArray |
Executes a query and returns the result as a list or array. |
Include |
Specifies related entities to be included in the query results. |
OrderBy /ThenBy |
Specifies ordering criteria for query results. |
FromSqlRaw |
Executes a SQL query directly on the database and returns the results as entities. |
Right click on Project Name -> Manage NuGet Packages -> Search - Microsoft.EntityFrameworkCore.SqlServer -> Select Version - 7.0.11 -> Install