[英]HTTP 404 Server Error in '/' Application. in ASP.NET MVC 4
`首先,這是我的第一個 MVC 代碼 & 我試圖在該站點中搜索問題的解決方案 & 我檢查了所有可能的情況,例如 routeconfig 文件、控制器、操作屬性 & 我嘗試在 Web 的指定頁面中放置適當的值項目屬性選項卡。 但它仍然顯示相同的錯誤。 請一些幫助。
這是我的路由配置文件
namespace Deepak_MVC_2
{
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 = "Student", action = "GetStudents", id = UrlParameter.Optional }
);
}
}
}
特定頁面條目:Student/GetStudents
namespace Deepak_MVC_2.Controllers
{
public class StudentController : Controller
{
public ActionResult GetAllStudent()
{
StudentModelManager smm = new StudentModelManager();
List<StudentModel> lsm = smm.GetAllStudentInfo();
ActionResult ar = View("GetStudents",lsm);
return ar;
}
}
}
更新您的控制器的操作以匹配您想要的視圖。 有了那個,您實際上可以在返回視圖時刪除名稱,因為約定會將ViewName
與操作名稱匹配。
namespace Deepak_MVC_2.Controllers
{
public class StudentController : Controller
{
public ActionResult GetStudents()
{
StudentModelManager smm = new StudentModelManager();
List<StudentModel> lsm = smm.GetAllStudentInfo();
ActionResult ar = View(lsm);
return ar;
}
}
}
這將允許
GET /Student/GetStudents
與圖像中的正確視圖相匹配
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.