Hello, I'm new here. I just recently installed Umbraco, and I've been looking through how everything works. I've had success with most of it, but I'm having trouble implementing a surface controller. From the tutorials I read, it seems that it can be done as a package or simply by placing it into a controllers directory, but I guess I must be missing something. I added a "Controllers" directory to the root folder, and added a class for the controller. But when I try to create a macro of type ChildAction, it does not come up. Here is the code I used for my controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Cms.Web.Context;
using Umbraco.Cms.Web;
using Umbraco.Cms.Web.Surface;
namespace MyProject.Controllers
{
// I tried it with or without this data annotation
[Surface("6d818fa0-fc6a-46a0-a33b-b454ffab7d80")]
public class TestSurfaceController : SurfaceController
{
//Constructor
public TestSurfaceController(IRoutableRequestContext requestContext)
: base(requestContext)
{
}
[ChildActionOnly]
public PartialViewResult processFormData(Contact contact)
The tutorial I read said that it was possible to do it without having to create a plug-in. I could try the plug-in method, but, initially, this method seemed simpler. I shouldn't need the [assembly: AssemblyContainsPlugins] if I'm not doing it as a plug-in, should I? If so, does that mean that the controller needs to be compiled? Also, where is the AssemblyInfo.cs file supposed to be in the project?
I think I might as well figure out how to make a plug-in--I'll probably have to know how to do that at some point anyway. But, the tutorial that I was following was http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-5-Surface-Controllers.aspx, which suggests that you do not actually need to use a plug-in to make a surface controller (and a couple other tutorials, I think, said similar things). I did create an AssemblyInfo.cs file in the Properties directory of the main Umbraco project, but that didn't help. I guess what I meant by not compiling the controller was not compiling it as a separate dll, which, as I understand, is what you need to do to create a plug-in.
I'm having the same issue with the Child Action being missing from the drop down, I've followed the steps a number of times with and without attributes. Can anyone post a basic VS solution so I can be sure I haven't missed anything?
There's a JavaScript error on the macros page in Back Office which I hope isn't affecting the Child Actions being pulled in?!
I as well am having issues with this. I'm trying to create a simple controller that will return some JSON to an AJAX call (via the non plug-in approach) and it doesn't even appear to be finding the controller in the controllers folder. It is just looking in the /Umbraco path.
Dont forget, controllers have to be compiled. I just make a new project in VS, which I then reference. It is not enough that you have a folder called controllers.
You don't have to make a plugin for it nor add anything to assemblyinfo.
Surface controller not appearing
Hello, I'm new here. I just recently installed Umbraco, and I've been looking through how everything works. I've had success with most of it, but I'm having trouble implementing a surface controller. From the tutorials I read, it seems that it can be done as a package or simply by placing it into a controllers directory, but I guess I must be missing something. I added a "Controllers" directory to the root folder, and added a class for the controller. But when I try to create a macro of type ChildAction, it does not come up. Here is the code I used for my controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Cms.Web.Context;
using Umbraco.Cms.Web;
using Umbraco.Cms.Web.Surface;
namespace MyProject.Controllers
{
// I tried it with or without this data annotation
[Surface("6d818fa0-fc6a-46a0-a33b-b454ffab7d80")]
public class TestSurfaceController : SurfaceController
{
//Constructor
public TestSurfaceController(IRoutableRequestContext requestContext)
: base(requestContext)
{
}
[ChildActionOnly]
public PartialViewResult processFormData(Contact contact)
{
if (contact == null)
{
contact = new Contact();
}
return PartialView("processFormData", contact);
}
}
public class Contact
{
public string FirstName;
public string LastName;
public string Email;
}
}
Did you add the following to your AssemblyInfo.cs file?
using Umbraco.Cms.Web;
[assembly: AssemblyContainsPlugins]
That is the way Umbraco knows that is should look for plugins in the dll.
Hey, thanks for the response!
The tutorial I read said that it was possible to do it without having to create a plug-in. I could try the plug-in method, but, initially, this method seemed simpler. I shouldn't need the [assembly: AssemblyContainsPlugins] if I'm not doing it as a plug-in, should I? If so, does that mean that the controller needs to be compiled? Also, where is the AssemblyInfo.cs file supposed to be in the project?
As I understand it, you always need to include that attribute. The AssemblyInfo.cs file should be on the Properties folder in your project.
I don't know if it is possible to crate a controller without compiling it. Also I don't know why you would want to?
I think I might as well figure out how to make a plug-in--I'll probably have to know how to do that at some point anyway. But, the tutorial that I was following was http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-5-Surface-Controllers.aspx, which suggests that you do not actually need to use a plug-in to make a surface controller (and a couple other tutorials, I think, said similar things). I did create an AssemblyInfo.cs file in the Properties directory of the main Umbraco project, but that didn't help. I guess what I meant by not compiling the controller was not compiling it as a separate dll, which, as I understand, is what you need to do to create a plug-in.
I'm having the same issue with the Child Action being missing from the drop down, I've followed the steps a number of times with and without attributes. Can anyone post a basic VS solution so I can be sure I haven't missed anything?
There's a JavaScript error on the macros page in Back Office which I hope isn't affecting the Child Actions being pulled in?!
I as well am having issues with this. I'm trying to create a simple controller that will return some JSON to an AJAX call (via the non plug-in approach) and it doesn't even appear to be finding the controller in the controllers folder. It is just looking in the /Umbraco path.
Dont forget, controllers have to be compiled. I just make a new project in VS, which I then reference. It is not enough that you have a folder called controllers.
You don't have to make a plugin for it nor add anything to assemblyinfo.
is working on a reply...