2016-11-12 28 views
1

對於我的一個類,我剛開始學習如何在ASP.Net MVC5中開發Web應用程序。我們需要做的一件事是重新設計一個簡單的用戶帳戶管理器的視圖,並且已經向我們提供了可供處理和修改的代碼。學習ASP.Net MVC並在'/'應用程序中構建用戶管理器服務器錯誤

問題是,當我真正在Visual Studio中運行代碼時,出現了404錯誤,說Server Error in '/' Application

我相當肯定代碼在教室中顯示時工作,但我無法在這裏工作。

這裏的示例代碼,對於那些有興趣:

UserManagerController.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 

namespace CS610W6.Controllers 
{ 
    public class UserManagerController : Controller 
    { 
     // 
     // GET: /UserManager/ 
     public ActionResult Index() 
     { 
      //Use the application's DB context to access the Identity framework's users 
      var UserList = new CS610W6.Models.ApplicationDbContext().Users.ToList(); 

      //Pass the UserList to the view 
      return View(UserList); 
     } 
    } 
} 

index.cshtml

@model List<CS610W6.Models.ApplicationUser> 
@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 
@foreach (var item in Model) 
{ 
    @item.UserName<br /> 
    @item.PasswordHash<br /> 
    @item.Id<br /> 
    @Html.ActionLink("Edit", "Edit", new { id = item.Id }) 
} 

編輯:這裏是的全文錯誤,如瀏覽器所示,

'/'應用程序中的服務器錯誤。

無法找到該資源。

說明:HTTP 404。您正在尋找(或它的 一個依賴項)的資源可能已被刪除,更名,或者是 暫時不可用。請檢查以下URL並確定 拼寫正確。

請求的URL:/Views/index.cshtml

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.34274

+1

加入你的完整錯誤。 –

+0

當你確切地得到錯誤? –

回答

3

當你是新來的MVC,我想,當你試圖在第一次運行程序,你得到這個錯誤。

正如我們在您的錯誤中可以看到的,請求的網址是/Views/index.cshtml

此錯誤僅表示應用程序無法找到任何路線。 您可以用URL yourdomain/UserManager/Index

檢查或者你可以設置默認的行動做出改變RouteConfig

routes.MapRoute(
       name: "Default", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "UserManager", action = "Index", id = UrlParameter.Optional } 
      ); 

這裏也是一個很好的文檔ASP.NET Routing

希望這有助於!

+1

謝謝!這工作。 – user2309750

相關問題