Asp.net mvc 2 怎么了?请参阅下面的编码
我创建了一个personcontroller并编写了上述代码。当我运行程序时,它总是给asp.NETMVC2默认页面。如何将personcontroller设置为我的起始页?您需要在Global.asax.cs中更改路由。如果希望索引操作成为默认路由,则需要这样的路由Asp.net mvc 2 怎么了?请参阅下面的编码,asp.net-mvc-2,Asp.net Mvc 2,我创建了一个personcontroller并编写了上述代码。当我运行程序时,它总是给asp.NETMVC2默认页面。如何将personcontroller设置为我的起始页?您需要在Global.asax.cs中更改路由。如果希望索引操作成为默认路由,则需要这样的路由 using System.Web; using System.Web.Mvc; namespace MvcApplication2.Controllers { public class PersonController
using System.Web;
using System.Web.Mvc;
namespace MvcApplication2.Controllers
{
public class PersonController : Controller
{
//
// GET: /Person/
//string fname { get; set; }
//string lname { get; set; }
public string Index()
{
return "This is the first";
}
public string welcome()
{
return "welcome";
}
}
}
routes.MapRoute(
"Web.Default",
"{controller}/{action}/{id}",
new { controller = "Person", action = "Index", id = "" });
routes.MapRoute(
"Web.Default",
"{controller}/{action}/{id}",
new { controller = "Person", action = "welcome", id = "" });