当我尝试发布“关于控制器”的插入页面时,我的标题出现错误。我认为这是因为路由,但我在编码中看不到任何问题。
我的路线如下。
` 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?}"
);
});`
我的控制器如下
` [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();
}
}`
我的观点如下
`@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>
`
您能帮我看看这里可能出现什么问题吗?我已经在论坛搜索但找不到正确的答案
我发现问题了。关于路由,我将管理端点置于默认端点之上。问题解决了。