0

I have an MVC application and some libraries that is it referring to. In one of the libraries I have created a controller class. However, it never seems to reach the controller from this library when navigating to the controller/action name.

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";
    }

    }
}

When I browse to localhost/CustomPrint/Index I get:

Server Error in '/' Application.

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: /CustomPrint/Index

Wesman80
  • 67
  • 7
  • 1
    Check this http://stackoverflow.com/questions/11077554/controller-in-separate-assembly-and-routing – Murali Murugesan Jun 06 '14 at 09:46
  • @Murali Yes, I have seen that post. However, in his case he is able to call the controller in the library. I do not get that far. – Wesman80 Jun 06 '14 at 09:53
  • Any reasons why you are creating a controller inside a different library? Generally the project with controller related classes would be the main entry point of the application and the other classes like services, utilities, domain, data objects will be kept in a different project.. – Muthu Jun 06 '14 at 10:15
  • 1
    @Muthu Because this will be handled as a plugin. Adding custom views and controllers to the application without changing the standard. – Wesman80 Jun 06 '14 at 10:24
  • It seems routes are not configured properly in your application.. – Anupam Singh Jun 06 '14 at 11:49
  • @AnupamSingh ok, but should the default route not being able to get this? routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional} – Wesman80 Jun 06 '14 at 12:13
  • I have read your comment after last answer. if this happen then create new MVC application. Might be some assembly reference missing. – Anupam Singh Jun 06 '14 at 12:30

1 Answers1

0

Try This :

it`s your controller code :

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

    {
    public class CustomPrintController : Controller
    {

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

    }
}

Now create a View for your Index Action by Add View option :

it`s your Index.cshtml code :

@{
    ViewBag.Title = "Index";
}

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

Hopefully it works...!

Amit
  • 823
  • 7
  • 13