2014-06-06 25 views
0

我有一個MVC應用程序和它引用的一些庫。在其中一個庫中,我創建了一個控制器類。但是,在導航到控制器/操作名稱時,它似乎從未從此庫到達控制器。來自庫的MVC控制器不會被調用

using System; 
using System.Web; 
using System.Web.Mvc; 

namespace Solution.Lib.Test 
{ 
    public class CustomPrintController : Controller 
    { 

    [HttpGet] 
    public string Index() 
    { 
     return "Solution.Lib.Test says Hi"; 
    } 

    } 
} 

當我瀏覽到localhost/CustomPrint /索引我得到:在 '/' 應用

服務器錯誤。

無法找到該資源。

說明:HTTP 404.您正在查找的資源(或其某個依賴項)可能已被刪除,名稱已更改或暫時不可用。請檢查以下網址並確保它拼寫正確。

請求的URL:/ CustomPrint /索引

+1

檢查此問題http://stackoverflow.com/questions/11077554/controller-in-separate-assembly-and-routing –

+0

@Murali是的,我看過那篇文章。但在他的情況下,他可以打電話給圖書館的管理員。我沒有那麼遠。 – Wesman80

+0

你爲什麼要在不同的庫中創建一個控制器的原因?一般來說,與控制器相關的類的項目將是應用程序的主要入口點,其他類如服務,實用程序,域,數據對象將保存在不同的項目中。 – Muthu

回答

0

試試這個:

它了控制器代碼:

using System; 
using System.Web; 
using System.Web.Mvc; 

    { 
    public class CustomPrintController : Controller 
    { 

    [HttpGet] 
    public ActionResult Index() 
    { 
     return View(); 
    } 

    } 
} 

現在create a ViewIndex Action通過Add View選項:

它您的Index.cshtml代碼:

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>String</h2> 
<p> 
    namespace Solution.Lib.Test Says Hi 
</p> 

希望它能起作用......!

+0

不幸的是,它不起作用,我在View()返回一個斷點,但它從來沒有命中。 – Wesman80

相關問題