Umbraco Noob here, I have found the documentation to be very underdeveloped for Umbraco 7 as it seems to rely on people having used prior versions.
I have created a surface controller and uploaded it to the site.
I have tried creating it VS2015 and it does not work, the documentation is incredibly light on any details as to how it should be implemented exactly. (should it use namespaces etc.)
Yes put the cs file in the controllers folder and make sure there is a corresponding action cshtml file in a folder named the same as the controller.
Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
public class ClassifiedController : Umbraco.Web.Mvc.SurfaceController
{
// GET: Classified
[HttpPost]
public ActionResult index()
{
return View();
}
}
First problem is you should´nt use [HttpPost] above your ActionResult. Either remove that or use [HttpGet]. This is not Umbraco specific but more a MVC standard: http://www.tutorialsteacher.com/mvc/actionverbs-in-mvc
Second problem is Im not sure what Url you are requesting?
All locally declared controllers get routed to:
/umbraco/surface/{controllername}/{action}/{id}
So in your scenario, you URL will be /Umbraco/Surface/Classified/Index
Based on your images im not sure if it´s actually a SurfaceController that you want to use, since SurfaceControllers are used for MVC Child Actions and for handling form data submissions and not for rendering complete pages. I think whatr you want is a Custom Controller (also called RenderMvcController and Hijacking Umbraco Routes). https://our.umbraco.org/documentation/reference/routing/custom-controllers.
Sorry Dennis, I didn't mean to leave the httppost in, it is indeed for taking in form data so it will eventually be required to be a post call and will attempt to redirect to a particular page.
/Umbraco/Surface/Classified/index does not exist after uploading the file to the controllers, however /Classified does.
The documentation you link to is exactly what I was reading, it is very light and skips info about what usings are present, whether namespaces are used etc.
Try to upload the /Controllers/ClassifiedController.cs + Views/Classified/Index.cshtml + and your solution .bin file to the server and see how that works.
Also, here is my code, so you can see namespaces used:
/Controllers/ClassifiedController.cs
using System.Web.Mvc;
using Umbraco.Web.Mvc;
namespace MyUmbracoSite.Controllers
{
public class ClassifiedController : SurfaceController
{
// GET: Classified
public ActionResult Index()
{
return View();
}
}
}
So in the above example, you need to upload the /Bin/MyUmbracoSite.bin file to the server.
Looking at your picture of your file-structure. Have you installed Umbraco in this solution? I cant see any Umbraco specific folder in your file structure like the Config folder, media, Umbraco or Umbraco_Client. Or maybe they are just hidden?
If you have Umbraco successfully installed i have no idea why your solution cant find Umbraco.Web.Mvc, sorry.
Ok, so this was a project created from Azure using teamviewer, it turns out it does not work correctly as it does not 'pull' down half the required information needed for compilation in Visual studio.
So it would be ok as long as you don't need surface controllers
Solution was to create a new EMPTY asp project, do NOT allow MVC to install as it creates conflicts with a version of MVC installed with the nuget package of Umbraco.
Of course that meant I had to package up my old site and load it onto the new instance, which caused it's own mixed bag of issues.
A couple of followup questions: I assume I have to create the folder controllers for surface controllers?
When you refer to MyUmbracoSite.bin this would be the MyUmbracoSite.dll.
Yeah it did´nt sound like you had all the files you needed.
Glad it worked out for you eventually!
Follow up question 1: Actually you can place your SurfaceController anywhere you want in you project and Umbraco will still pick this Controller up. But yeah it looks a lot cleaner to have a dedicated folder called "Controllers" in your project, so it looks and feels like a regular MVC application.
Follow up question 2: Yes, hehe, thats a typo. It should be MyUmbracoSite.dll.
Surface Controllers
Umbraco Noob here, I have found the documentation to be very underdeveloped for Umbraco 7 as it seems to rely on people having used prior versions.
I have created a surface controller and uploaded it to the site.
I have tried creating it VS2015 and it does not work, the documentation is incredibly light on any details as to how it should be implemented exactly. (should it use namespaces etc.)
Yes put the cs file in the controllers folder and make sure there is a corresponding action cshtml file in a folder named the same as the controller.
Controller:
index.cshtml
Error message below, I believe it is happening when it tries to find routes or something to that effect.
Stacktrace:
Are there any actual tutorials out there to create and apply surface controllers? Anybody know what is going on?
If you have a solution, please do not assume I know what libraries you are using and paste all your code.
Hi Damien.
First problem is you should´nt use
[HttpPost]
above your ActionResult. Either remove that or use[HttpGet].
This is not Umbraco specific but more a MVC standard: http://www.tutorialsteacher.com/mvc/actionverbs-in-mvcSecond problem is Im not sure what Url you are requesting?
So in your scenario, you URL will be /Umbraco/Surface/Classified/Index
Also what documentation have you been reading? This one? https://our.umbraco.org/documentation/reference/routing/surface-controllers.
Based on your images im not sure if it´s actually a SurfaceController that you want to use, since SurfaceControllers are used for MVC Child Actions and for handling form data submissions and not for rendering complete pages. I think whatr you want is a Custom Controller (also called RenderMvcController and Hijacking Umbraco Routes). https://our.umbraco.org/documentation/reference/routing/custom-controllers.
Also if you are new to Umbraco and find it difficult, i recommend you to get a subscrition to http://www.umbraco.tv/ for great video tutorials and maybe look up a Umbraco Traning center https://umbraco.com/products/training.
Best of luck to you!!
Sorry Dennis, I didn't mean to leave the httppost in, it is indeed for taking in form data so it will eventually be required to be a post call and will attempt to redirect to a particular page.
/Umbraco/Surface/Classified/index does not exist after uploading the file to the controllers, however /Classified does.
The documentation you link to is exactly what I was reading, it is very light and skips info about what usings are present, whether namespaces are used etc.
Have you build the solution?
Try to upload the /Controllers/ClassifiedController.cs + Views/Classified/Index.cshtml + and your solution .bin file to the server and see how that works.
Also do you have it working locally?
Not working locally as VS does not recognise the Umbraco.Web.Mvc (only Umbraco.Web.UI available)
Also, here is my code, so you can see namespaces used:
/Controllers/ClassifiedController.cs
So in the above example, you need to upload the /Bin/MyUmbracoSite.bin file to the server.
This does not exist according to VS2015
Is there any way of creating surface files or making a form to post back to Umbraco without using js or a surface controller?
Or even making the surface controller from within the Umbraco interface as it tries to make you do for everything else.
Hi Damien.
Looking at your picture of your file-structure. Have you installed Umbraco in this solution? I cant see any Umbraco specific folder in your file structure like the Config folder, media, Umbraco or Umbraco_Client. Or maybe they are just hidden?
If you have Umbraco successfully installed i have no idea why your solution cant find Umbraco.Web.Mvc, sorry.
Ok, so this was a project created from Azure using teamviewer, it turns out it does not work correctly as it does not 'pull' down half the required information needed for compilation in Visual studio.
So it would be ok as long as you don't need surface controllers
Solution was to create a new EMPTY asp project, do NOT allow MVC to install as it creates conflicts with a version of MVC installed with the nuget package of Umbraco.
Of course that meant I had to package up my old site and load it onto the new instance, which caused it's own mixed bag of issues.
A couple of followup questions: I assume I have to create the folder controllers for surface controllers?
When you refer to MyUmbracoSite.bin this would be the MyUmbracoSite.dll.
Ah ok i understand.
Yeah it did´nt sound like you had all the files you needed.
Glad it worked out for you eventually!
Follow up question 1: Actually you can place your SurfaceController anywhere you want in you project and Umbraco will still pick this Controller up. But yeah it looks a lot cleaner to have a dedicated folder called "Controllers" in your project, so it looks and feels like a regular MVC application.
Follow up question 2: Yes, hehe, thats a typo. It should be MyUmbracoSite.dll.
Cheers man, thanks for all the info.
No problem! Have a great day! :)
is working on a reply...