对于用户数,您可以尝试
public class HomeController : Controller
{
private ApplicationDbContext _context;
public HomeController(ApplicationDbContext context)
{
_context = context;
}
public IActionResult Index()
{
return View();
}
public IActionResult About()
{
ViewData["UserCount"] = _context.Users.Count();
ViewData["Message"] = "Hello Word";
return View();
}
}
对于显示count on按钮,您可以尝试
@{
ViewData["Title"] = "About";
}
<h2>@ViewData["Title"].</h2>
<h3>@ViewData["Message"]</h3>
<p>Use this area to provide additional information.</p>
<button>@ViewData["UserCount"]</button>