我正试图转到教程中的以下页面:
https://localhost:44336/HelloWorld/Welcome
我创建了一个ASP.NET Core MVC web应用程序项目,并在Controllers
文件夹中添加了一个名为HelloWorldController
的控制器,并使用了以下命令而不是以前的命令。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Text.Encodings.Web;
namespace MvcMovie.Controllers
{
public class HelloWorldController : Controller
{
//
// GET : /HelloWorld/
public string Index()
{
return "This is my default action...";
}
//
// GET : /HelloWorld/Welcome/
private string Welcome()
{
return "This is the Welcome action method...";
}
}
}
我遇到的问题是它打开了以下页面:
https://localhost:44336/HelloWorld
但它不会打开以下页面:
https://localhost:44336/HelloWorld/Welcome
请帮我
因为您的Welcome
是private
:
修改为public
:
public string Welcome()
{
return "This is the Welcome action method...";
}
关于它们的不同,你可以在这里看到。
当它们是网页时,您的操作不应该是私有的。你应该公开