app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Menu}/{action=Index}/{id?}");
});
//然后我的MenuController中只有一个Index的action
一运行,程序就会进入路由的部分,然后报错
InvalidOperationException: Multiple constructors accepting all given argument types have been found in type 'PesitcideWMS.Controllers.MenuController'. There should only be one applicable constructor.
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.TryFindMatchingConstructor(Type instanceType, Type[] argumentTypes, ref ConstructorInfo matchingConstructor, ref Nullable[] parameterMap)
这是MenuController
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using PesitcideWMS.Domain.Entity;
using PesitcideWMS.Models;
using PesitcideWMS.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace PesitcideWMS.Controllers
{
[Authorize]
public class MenuController : Controller
{
private readonly ILogger<MenuController> _logger;
private readonly CoreDbContext _CoreDbContext;
public MenuController(ILogger<MenuController> logger)
{
_logger = logger;
}
public MenuController(CoreDbContext CoreDbContext)
{
_CoreDbContext = CoreDbContext;
}
//public async Task<IActionResult> InitView()
//{
// ViewBag.menu_tree = await _CoreDbContext.MenuView.ToListAsync();
// return View();
//}
public IActionResult Index()
{
ViewBag.shouye = "/Home/Index";
return View();
}
[HttpPost]
public ActionResult<string> GetLeftNavAsync()
{
List<MenuView> allValue = new List<MenuView>();
allValue = _CoreDbContext.MenuView.ToList();
List<TreeJsonModel> a = Tree.GetTreeJson(allValue);
return JsonConvert.SerializeObject(a);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}