1

I just started learning Umbraco, I have started small project just to learn Umbraco. I am having problem in creating custom controller. I have a link on my page for user to browse all the products:

@Html.ActionLink("View more", "Index", "Product", null, new { title = "Browse all Products" })

Controller

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

namespace Test.Controllers
{
    public class ProductController : Umbraco.Web.Mvc.RenderMvcController
    {
        public override ActionResult Index(RenderModel model)
        {
            return View("Products");
        }
    }
}

For some reason the web page show a the link with blank href

<a href="" title="Browse all Products">View more</a>
Djensen
  • 1,337
  • 1
  • 22
  • 32
Fahad
  • 173
  • 1
  • 12
  • According to [this post](http://stackoverflow.com/questions/33035660/actionlink-generate-empty-href) your controller has to inherit from **Umbraco.Web.Mvc.SurfaceController** in order for the route to be picked up. Is this an option for you? – Rob Purcell Apr 13 '16 at 13:24
  • Hi, I have changed it to inherit from SurfaceController. But now when I try to run I get error HTTP 404 the resouce not found at /umbraco/Surface Where as all my views are stored in View folder. Not sure how to change it to look for views in View folder. – Fahad Apr 13 '16 at 14:04

1 Answers1

1

You don't necessarilly have to inherit from SurfaceController, as they are typically used for rendering MVC Child Actions and for handling form data submissions. In your case, a controller inheriting from Umbraco.Web.Mvc.RenderMvcController should be enough.

First check the Settings section of Umbraco and make sure that there is a Document Type called Product. Umbraco follows this convention for routing, so all pages of type Product will be routed to your ProductController. This routing convention might also help the HtmlHelper construct the action link correctly.

According to the documentation, the mapping works as follows:

  • Document Type name = controller name
  • Template name = action name
  • if no action matches or is not specified then the 'Index' action will be executed.

Finally, make sure that your controller action returns the template view. For example, if using the default RenderModel type, you can simply return the Template view for the document type:

public override ActionResult Index(RenderModel model)
{
    return base.Index(model);
}
elolos
  • 4,310
  • 2
  • 28
  • 40
  • Hi, I followed yous instructions , now I am getting error : System.Exception: No physical template file was found for template Product I have checked in backoffice Umbraco and I cant see anything wromg with it. – Fahad Apr 18 '16 at 11:03
  • Does you document type have a template named "Product"? Also, can you see a file named "Product.cshtml" within your project's `Views` folder? – elolos Apr 18 '16 at 12:29