Page is not found:http://localhost:28196/About/Insert?area=Admin

41 Views Asked by At

When I try to post my Insert page for About Controller I am getting error as my title. I thougt that it is because of routing but I could not see any problem in my coding.

My routing as below.

        `  app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
              name: "areas",
              pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
            );
        });`

My Controller is as below

` [Area("Admin")]
public class AboutController : Controller
{

    private readonly IAboutService _aboutService;
    private readonly IMapper _mapper;
    IWebHostEnvironment _env;
    public AboutController(IAboutService aboutService, IMapper mapper, IWebHostEnvironment env)
    {
        _aboutService = aboutService;
        _mapper = mapper;
        _env = env;
    }

    public IActionResult AboutList()
    {
        List<ListAboutViewModel> list = new List<ListAboutViewModel>();

         list = _mapper.Map<List< ListAboutViewModel >> (_aboutService.TGetListAll());
        
        return View(list);
    }

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

    [HttpPost]
    public IActionResult Insert(CreateAboutViewModel createAboutViewModel, List<IFormFile>          files)
    {

       
        About viewModel = new About()
        {
            Description=createAboutViewModel.Description,
            ShortDescription=createAboutViewModel.ShortDescription,
            Title=createAboutViewModel.Title

           
        };

        bool imageResult;
        string imagePath = Upload.ImageUpload(files, _env, out imageResult);
        if (imageResult)
            viewModel.ImageUrl = imagePath;
        else
        {
            ViewBag.Message = imagePath;
            return View();
        }



        if (ModelState.IsValid)
        {
            _aboutService.TAdd(viewModel);
            RedirectToAction("AboutList");
        }
       return View();
    }
    }`

My View is as below

  `@model CreateAboutViewModel

  @{
  ViewData["Title"] = "Insert";
  Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
   }


 <div class="col-md-12">
 <div class="card">
     <div class="card-header">
        <h4>Hakkımızda Sayfası Oluşturma</h4>
     </div>
     <div class="card-body">
        <form asp-area="Admin" asp-controller="About" asp-action="Insert" method="post"     enctype="multipart/form-data">
            <div class="group-form">
                <label class="form-label">Başlık</label>
                <input asp-for="Title" class="form-control" placeholder="Başlık Giriniz">
            </div>
            <div class="group-form">
                <input type="file" asp-for="ImageUrl" name="files" accept=".png, .jpg, .jpeg" />
            </div>
            <div class="group-form">
                <textarea asp-for="ShortDescription" class="form-control" rows="3" placeholder="Hakkımızda kısa detay girişi yapınız."></textarea>
            </div>
           @* <div class="group-form">
                <div class="ckmain">
                    <div class="ckeditor-menu"></div>
                    <div id="crowenkeditor">
                     
                    </div>
                   
                </div> 
               
            </div>*@

            <div class="group-form">
                <textarea asp-for="Description" class="form-control" rows="3" placeholder="Hakkımızda kısa detay girişi yapınız."></textarea>
            </div>
          
            <button class="btn btn_primary" type="submit">Ekle</button>
        </form>
    </div>

`

Could you please help me what problem could be here? I already searched in forum but could not found proper answer

2

There are 2 best solutions below

1
Mukremin Buyukkulekci On

I have found the problem. Regarding the routing I take admin endpoint above the default endpoints. The problem is solved.

0
Fei Han On

Page is not found:http://localhost:28196/About/Insert?area=Admin

Please note the following:

  1. You pass area info through query string, but query string parameters are not directly involved in the route matching process by default in ASP.NET Core MVC, which would cause the request can not reach out into expected endpoint.

  2. And in general, routes with areas should be placed earlier in the route table as they're more specific than routes without an area.

  3. Besides, please check if you add @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers in _ViewImports.cshtml under the appropriate view folder of your areas to make Tag Helpers available to areas views.