无法从“视图”中的浏览器中查看页面

时间:2020-03-17 09:54:34

标签: asp.net-core razor-pages

我在MVC Core应用程序中创建了以下文件夹和页面: 查看->管理-> CreateRole.cshtml

重建页面后,我不愿意在浏览器中查看该页面。

This localhost page can’t be foundNo webpage was found for the web address: https://localhost:44310/Administration/createrole.cshtml
HTTP ERROR 404

可能是我的路由中出现问题吗?

startup.cs

 public void Configure(IApplicationBuilder app,
            IHostingEnvironment env, ApplicationDbContext context, RoleManager<ApplicationRole> roleManager, UserManager<ApplicationUser> userManager)
        {
            // 
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            SeedIdentity.Initialize(context, userManager, roleManager).Wait();
        }

下面的AdministrationController:

 public class AdministrationController : Controller
    {
        //private readonly RoleManager<IdentityRole> roleManager;
        RoleManager<IdentityRole> roleManager;
        UserManager<IdentityUser> userManager;
        public AdministrationController(RoleManager<IdentityRole> roleManager, UserManager<IdentityUser> userManager)
        {
            //_roleManager = roleManager;
            //_userManager = userManager;
        }
        /**
        public AdministrationController(RoleManager<IdentityRole> roleManager)
        {
            this.roleManager = roleManager;
        }**/

        [HttpGet]
        public IActionResult CreateRole()
        {
            return View();
        }

        [HttpPost]
        public async Task<IActionResult> CreateRole(CreateRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                IdentityRole identityRole = new IdentityRole
                {
                    Name = model.RoleName
                };
                IdentityResult result = await roleManager.CreateAsync(identityRole);
                if (result.Succeeded)
                {
                    return RedirectToAction("index", "home");
                }
                foreach (IdentityError error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

            }


            return View(model);
        }
    }

我想念什么吗?

0 个答案:

没有答案
相关问题