MVC - 无法导航到详细信息查看ASP.NET

时间:2013-03-10 08:43:40

标签: asp.net asp.net-mvc c#-4.0

您好,在我的MVC应用程序中,我正在尝试导航到详细信息视图

这是我在控制器中的代码

 public class CustomerController : Controller
{
    //
    // GET: /Customer/

    public ActionResult Index()
    {
        NorthWindEntity db = new NorthWindEntity();
        var Data = db.Customers;
        return View(Data);
    }
    public ActionResult Details(string id)
    {
        NorthWindEntity db = new NorthWindEntity();
        var Data = db.Customers.Where(e => e.CustomerID == id).Select(e => e).Single();
        return View(Data);
    }
}

这是全局asax中的代码

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Customer", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

这是导航主页中的代码

 <td>
            <%: Html.ActionLink("Edit", "Edit",new { id=item.CustomerID }) %> |
            <%: Html.ActionLink("Details", "Details", new { id = item.CustomerID })%> |
            <%: Html.ActionLink("Delete", "Delete", new { id=item.CustomerID })%>
        </td>

我创建了详细信息视图 像这样

enter image description here

但问题是,当我尝试导航到详细信息视图时,我收到此错误

 The resource cannot be found.
 Description: HTTP 404. The resource you are looking for (or one of its dependencies)
 could have been removed, had its name changed, or is temporarily unavailable. 
 Please review the following URL and make sure that it is spelled correctly.

 Requested URL: /Customer/Details/1

我很困惑,因为页面已经存在,我缺少什么。?

1 个答案:

答案 0 :(得分:0)

您可以尝试将aspx重命名为cshtml。 请参阅全局asax中的ProviderBinders和Routing