「東雲 忠太郎」の平凡な日常のできごと

「東雲 忠太郎」の平凡な日常のできごと

2024.02.28
XML
カテゴリ: C#.NET


// Startup.cs


using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Hosting;

using Microsoft.Extensions.Configuration;

using Microsoft.Extensions.DependencyInjection;

using Microsoft.Extensions.Hosting;


namespace HelloWorldApp

{

    public class Startup

    {

        public Startup(IConfiguration configuration)

        {

            Configuration = configuration;

        }


        public IConfiguration Configuration { get; }


        // This method gets called by the runtime. Use this method to add services to the container.

        public void ConfigureServices(IServiceCollection services)

        {

            services.AddControllersWithViews();

        }


        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

        {

            if (env.IsDevelopment())

            {

                app.UseDeveloperExceptionPage();

            }

            else

            {

                app.UseExceptionHandler("/Home/Error");

                app.UseHsts();

            }

            app.UseHttpsRedirection();

            app.UseStaticFiles();


            app.UseRouting();


            app.UseAuthorization();


            app.UseEndpoints(endpoints =>

            {

                endpoints.MapControllerRoute(

                    name: "default",

                    pattern: "{controller=Home}/{action=Index}/{id?}");

            });

        }

    }

}


// HomeController.cs


using Microsoft.AspNetCore.Mvc;


namespace HelloWorldApp.Controllers

{

    public class HomeController : Controller

    {

        public IActionResult Index()

        {

            return View();

        }


        [HttpPost]

        public IActionResult Index(string name)

        {

            ViewData["Message"] = "Hello, " + name + "!";

            return View();

        }

    }

}


<!-- Index.cshtml -->


@{

    ViewData["Title"] = "Home Page";

}


<h2>@ViewData["Title"]</h2>


<form asp-controller="Home" asp-action="Index" method="post">

    <label for="name">Enter your name:</label><br />

    <input type="text" id="name" name="name" /><br />

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

</form>


@if (ViewData["Message"] != null)

{

    <p>@ViewData["Message"]</p>

}







お気に入りの記事を「いいね!」で応援しよう

Last updated  2024.02.28 05:15:23


【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! -- / --
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x

© Rakuten Group, Inc.
Create a Mobile Website
スマートフォン版を閲覧 | PC版を閲覧
Share by: