这是我的控制者:
using System.Web;
using System.Web.Mvc;
namespace MvcMovie.Controllers
{
public class HelloWorldController : Controller
{
//
// GET: /HelloWorld/
public ActionResult Index()
{
return View();
}
//
// GET: /HelloWorld/Welcome/
public string Welcome(string name)
{
return HttpUtility.HtmlEncode("Hello " + name + ", NumTimes is: 55 " );
}
}
}
这是我的路线:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
但每当我通过网址:http://localhost:61114/helloworld/welcome/scott
我的输出是:你好,NumTimes是:55 而不是Hello Scott,NumTimes是:55
答案 0 :(得分:1)
您的参数名称应为id
或
您的路线应为{name},name = UrlParameter.Optional