create a link to SurfaceController in Umbraco

1.4k views Asked by At

As I am new to Umbraco, I have not quite understood the routing mechanisms it seems to have.

I have a custom surface controller myProject.Controllers.CompanySurfaceController with a getCompanyList() and getCompany(int companyId) function.

The basic idea is to get the list of companies from the db, render the partial view with classic <a> links to the getCompany(..)function and retrieve/display that company from the db.

Everything is working fine except one thing: I cannot grasp how to create the <a> links to the child action of the controller! I have no problem including child actions in partial views when POSTing and using Html.Action.

I have tried @Html.ActionLink and other helpers but the closest I get to, is a link for /umbraco/Surface/CompanySurface/Company, which doesn't work of course and it does not include the id parameter (e.g. Company/3).

I have also tried to put the controllers in the umbraco/Surface namespace without luck (and it does not seem necessary).

What am I missing here?

2

There are 2 answers

0
lape On BEST ANSWER

I ended up using the classic way of doing GET parameters instead. It works because i fetch all companies from the DB and handle everything in one controller (e.g. EditCompany). Then I can pass the /EditCompany?companyId=xx

It is not pretty but it is only needed for secure pages so I do not worry about SEO for now.

If we really need to make this work with custom controllers we need to implement a custom IContentFinder in Umbraco instead.

5
dampee On

First of all, I am wondering why you don't put the companies as nodes in your content tree by giving them an own document type. That would produce very simple code like this:

@foreach(var company in Model.Children) 
{
  <a href="@company.Url">@company.Name</a>
}

If the appoach above is not an option and you need to pull data out of an external (non umbraco) table, then do what you are doing. Except, you can not create a <a> to a child action! This is not something umbraco prohibits, this is ASP.Net MVC protection so users can't "hack" into your child actions. What your really want to use is a RenderMvcController (see documentation). There is another question digging into the difference between RenderMvcController and SurfaceController.