2014-02-05 15 views
0

我想爲我的網站添加一個新的視圖,但我一直在'/'應用程序中獲取錯誤服務器錯誤。我的視圖鏈接到控制器,我的路由配置文件有正確的路徑。任何幫助將不勝感激。服務器錯誤'/'應用程序MVC 5

檔案控制器

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

    namespace Bitev2.Controllers 
    { 
     public class ProfileController : Controller 
     { 
      // 
      // GET: /Profile/ 
      public ActionResult Index() 
      { 
       return View(); 
      } 

      // 
      // GET: /Profile/Details/5 
      public ActionResult Details(int id) 
      { 
       return View(); 
      } 

      // 
      // GET: /Profile/Create 
      public ActionResult Create() 
      { 
       return View(); 
      } 

      // 
      // POST: /Profile/Create 
      [HttpPost] 
      public ActionResult Create(FormCollection collection) 
      { 
       try 
       { 
        // TODO: Add insert logic here 

        return RedirectToAction("Index"); 
       } 
       catch 
       { 
        return View(); 
       } 
      } 

      // 
      // GET: /Profile/Edit/5 
      public ActionResult Edit(int id) 
      { 
       return View(); 
      } 

      // 
      // POST: /Profile/Edit/5 
      [HttpPost] 
      public ActionResult Edit(int id, FormCollection collection) 
      { 
       try 
       { 
        // TODO: Add update logic here 

        return RedirectToAction("Index"); 
       } 
       catch 
       { 
        return View(); 
       } 
      } 

      // 
      // GET: /Profile/Delete/5 
      public ActionResult Delete(int id) 
      { 
       return View(); 
      } 

      // 
      // POST: /Profile/Delete/5 
      [HttpPost] 
      public ActionResult Delete(int id, FormCollection collection) 
      { 
       try 
       { 
        // TODO: Add delete logic here 

        return RedirectToAction("Index"); 
       } 
       catch 
       { 
        return View(); 
       } 
      } 
     } 
    } 

資料視圖

@{ 
    ViewBag.Title = "Profile"; 
} 

<h2>Profile</h2> 

路由配置文件

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

namespace Bitev2 
{ 
    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 = "Home", action = "Index", id = UrlParameter.Optional } 
      ); 
     } 
    } 
+0

對於哪個網址,您遇到此錯誤?你可以分享該網址嗎? – ramiramilu

+0

你有家庭控制器嗎? –

+0

我想,你必須在運行時輸入id或你正在使用哪種認證。檢查web.config文件。 –

回答

2

目前只有以下網址,通過您的控制器結構允許 -

/profile/index 
/profile/details/id 
/profile/create 
/profile/edit/id 
/profile/delete/id 

投遞操作支持網址 -

/profile/create 
/profile/edit/id 
/profile/delete/id 

,且您嘗試/profile/profile它不存在。所以這就是你出錯的原因。要麼創建配置文件操作,要麼嘗試使用Custom Errors section來處理404錯誤。

+0

謝謝你解決了我的問題 – Dolaps

1

有了這些默認它應該工作:

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

控制器= 「檔案」

相關問題