Questions tagged [surface-controller]

A Surface Controller is an MVC controller that interacts with the front-end (or render layer) of Umbraco.

A Surface Controller is an MVC controller that interacts with the front-end (or render layer) of Umbraco. An example of a Surface Controller could be a controller that has a Child Action used to display a Twitter Feed, or a controller that has an Action to accept some posted information from a form. Child Actions on Surface Controller will probably be primarily used for Child Action Macros in Umbraco v5.

Since Surface Controllers are plugins, this means that you can create a package that contains Surface Controllers to distribute whatever front-end functionality you like to Umbraco developers. Surface Controllers, just like Tree Controllers and Editor Controllers get automatically routed for you.

To create a surface controller for use in a plug-in you create a class within a project with a reference to System.Web.Mvc and Umbraco.CMS.Web, with the following setup:

•Inherits from SurfaceController

•Named with a suffix of "SurfaceController"

•Has a class attribute of Surface with a unique GUID

•Contains one or more action methods that return either PartialViewResult or ContentResult and are marked with the [ChildActionOnly] attribute

•The project AssemblyInfo.cs file must contain [assembly: AssemblyContainsPlugins] Otherwise you use standard MVC concepts such as view models and tightly or loosely bound views, either standalone or embedded. You deploy to your package folder as detailed in the previous post.

Using the Surface Controller

There are a couple of ways to make use of the surface controller once it has been built and deployed to the Umbraco application.

One is the standard MVC way - after all this is just a controller action returning a partial view or content result. So you can use @Html.Action. As it's a plug-in, which is created as it's own area, you need to specify the area the controller and action is found within, as follows:

@Html.Action("ActionName","ControllerName", new {area = "PackageName"})

Unfortunately as of writing, this doesn't seem to work. An error of "No route in the route table matches the supplied values." results. Hopefully will sort this out or determine if it's a bug to be fixed shortly.

In any case the better way is really to create a Child Action Macro. This is done via the Developer section and once created the deployed package, controller and action should be selectable from the list. You can then render the macro, e.g. in a template with:

@Umbraco.RenderMacro("artistList")
18 questions
2
votes
1 answer

Umbraco surface controller not submitting to backend with POST

I basically have a contact form, which I need to POST to my Umbraco backend. The frontend looks similar to this: using (Html.BeginUmbracoForm("HandleFormSubmit", "ContactForm", FormMethod.Post)) {
MortenMoulder
  • 6,138
  • 11
  • 60
  • 116
2
votes
1 answer

Umbraco No parameterless constructor defined for this object

I am trying to render a partial view in Umbraco. I have a BaseLayout.cshtml,Homepage.cshtml,BaseLayoutViewModel,HomepageViewModel This is my BaseLayout View @inherits Umbraco.Web.Mvc.UmbracoViewPage @{ Layout =…
harnamc
  • 541
  • 6
  • 20
2
votes
2 answers

How to Use ViewData and ViewBag with Umbraco Surface Controllers

I have just spent 2 hours trying to work out why when I put a string in to View.Bag/ViewData inside my Surface controller, when I try and get the string back in the view I get null. In the end I have solved the problem by putting the string in to a…
Ayo Adesina
  • 2,231
  • 3
  • 37
  • 71
2
votes
2 answers

create a link to SurfaceController in Umbraco

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…
lape
  • 41
  • 6
2
votes
3 answers

Umbraco 7 Partial View Macro Rendering

In Umbraco 7.0.3 I: Created a Data Type called Macro Container with Property editor of Macro container Created Document Type called Contact Form with Property called Body with Type Macro Container Created Partial View called _contactForm.cshtml…
Serj Sagan
  • 28,927
  • 17
  • 154
  • 183
1
vote
1 answer

Umbraco BlogComment Create Ajax

Hello im trying to post my blog comments the function works. but the whole site refreshes inside the div, i tried playing around with the partialview in the controller but im not sure what to do can anybody here point me in the right directtion, i…
1
vote
1 answer

Umbraco Async SurfaceController

I am working on a project (ASP.NET MVC 5) where I am using Umbraco 7.4.3. I am trying to implement the google analytics api along with oauth2. I used the sample code available on the google documentation platform. After authorizing with my google…
user2963570
  • 381
  • 6
  • 21
0
votes
1 answer

How to make Umbraco form with validation work correctly?

I couldn't find even one tutorial that correctly and fully explains how to make a form with validation. More specifically I have the following issue - when the errors are passed, the filled content by the user is lost. I am using Umbraco v7, but I…
mgPePe
  • 5,677
  • 12
  • 52
  • 85
0
votes
1 answer

Validate Umbraco Back Office Users programmatically

Im new to umbraco and currently faced with below issue. I have a requirement to validate for the existence of umbraco backoffice users (users in umbracoUser table) inside a SurfaceController by using a user entered username and a password, and this…
BUDDHIKA
  • 306
  • 2
  • 8
  • 23
0
votes
0 answers

Umbraco 7.6.3 Tests to Controller always fails

I have a serious issue with testings on Umbraco 7.6.3 because my test always get the same error: System.NullReferenceException : Object reference not set to an instance of an object. at DirectUmbraco.Models.ContactModel..ctor() in…
0
votes
1 answer

use RenderMvcController to filter a list in Umbraco

my goal is to create a list of contents (of specific docType) . in this list I have a filter button and two ddlist dynamically filled with children data. when user click the "filter" , the list should be updated by selected ddlist values. Is it…
Sara N
  • 1,079
  • 5
  • 17
  • 45
0
votes
1 answer

handle "Umbraco Forms" in umbraco 7.5

I'm a newbie in Umbraco , and cant understand some logics behind that. I use Umbraco 7.5 and installed Umbraco Forms. Just want to know how can I write .Net code for postback of the code? If I can use the controlers(RenderMVCControllers and…
Sara N
  • 1,079
  • 5
  • 17
  • 45
0
votes
1 answer

routing with multiple parameter in umbraco 7

I have a page like http://localhost:55617/knowledge-house/magazines/ in umbraco 7. Now I want to apply routing to the same when parameters are present in url say http://localhost:55617/knowledge-house/magazines/English/2012/. where 'English' &…
ghetal
  • 403
  • 2
  • 11
  • 30
0
votes
1 answer

Not all values in MVC form being posted

A little help or advice if any of you can? I have an MVC form (it's actually an Umbraco form/surface controller, but I don't know that that has any bearing on this), the model for which contains a list of objects being used to generate check-boxes…
Mark Johnson
  • 445
  • 1
  • 6
  • 11
0
votes
1 answer

Ajax.BeginForm posts to surface controller and updates target id with full page instead of partial view

Have been trying to get a member profile management area working with ajax as each section of the page is hidden within a show hide div. I have used ajax before in MVC applications but have never used it with umbraco surface controllers before. I'm…
1
2