Action Method in ASP.NET Core, IActionResult in ASP.NET Core, ActionResult MVC

 using Microsoft.AspNetCore.Mvc;


namespace ControllersAndActions.Controllers

{

    public class HomeController : Controller

    {

        public IActionResult Index()

        {

            return View();  //ViewResult, PartialViewResult, JsonResult etc

        }

        public string Display()

        {

            return "Welcome To Programentor";

        }

        public int DisplayId(int id)

        {

            return id;

        }

    }

}

Above File is ControllersAndActions\Controllers\HomeController.cs File








@{
    ViewData["Title"] = "Index";
}

<h1>Index</h1>
Above File is ControllersAndActions\Views\Home\Index.cshtml File






namespace ControllersAndActions
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);
            builder.Services.AddControllersWithViews();
            var app = builder.Build();

            app.MapControllerRoute(
                name:"default",
                pattern:"{controller=Home}/{action=Index}/{id?}"
                );

            //app.MapGet("/", () => "Hello World!");

            app.Run();
        }
    }
}
Above File is ControllersAndActions\Program.cs File
















Comments

Popular posts from this blog

Map, MapGet, MapPost, MapPut and MapDelete methods in ASP.NET Core MVC - Routing ASP.NET

Layout View In ASP.NET Core 6 | _Layout.cshtml ASP.NET | Master Page ASP.Net Core

Attribute Routing in ASP.NET Core MVC