Search code examples
asp.net-mvc-5asp.net-core-viewcomponent

MVC 5 ViewComponent namespace reference missing


I am using mvc 5 and creating ViewComponent. Facing namespace missing reference error.

The type or namespace name 'ViewComponent' could not be found (are you missing a using directive or an assembly reference?)

here is code sample

public class SumViewComponent : ViewComponent
{
    public IViewComponentResult Invoke(int a, int b)
    {
        return this.Content($"<span class=\"result\">{a + b}</span>");
    }
}

How can i resolve namespace issue, is it supported in mvc 5 application.


Solution

  • MVC 5 does not have ViewComponents, they were introduced with MVC 6. See this article