【发布时间】:2014-08-18 11:35:28
【问题描述】:
我在 asp mvc2 应用程序中制作控制器。之后我为这个控制器创建视图。
我将此控制器命名为“DisplayName” 并写出类似的东西:
public class DisplayName : Controller
{
//
// GET: /DisplayName/
public ActionResult Index()
{
return View();
}
public ActionResult DisplaySomething()
{
MojaKlasa objCustomer = new MojaKlasa();
objCustomer.ime = "Random ime";
objCustomer.broj = 10;
return View("DisplaySomething", objCustomer);
}
}
但是当我尝试在网络浏览器中显示并调用时:
http://localhost:xxxxx/DisplayName/DisplaySomething
我得到错误:
Server Error in '/' Application. The resource cannot be found.
我试图找出错误,然后我在 DisplayNameController 中看到一个示例并重命名控制器
现在我有:
public class DisplayNameController : Controller
{
//
// GET: /DisplayName/
public ActionResult Index()
{
return View();
}
public ActionResult DisplaySomething()
{
MojaKlasa objCustomer = new MojaKlasa();
objCustomer.ime = "Random ime";
objCustomer.broj = 10;
return View("DisplaySomething", objCustomer);
}
}
现在当我打电话时:
http://localhost:xxxxx/DisplayName/DisplaySomething
应用完美运行。
我的问题是下一个:这是否意味着每个控制器的名称都需要有“控制器”?为什么我不能只使用我想要的名称?
感谢
【问题讨论】:
标签: c# asp.net asp.net-mvc-2