Hi,
I have added my own controller and views using visual studio in to existing Umbraco application. In my views if I try to use layout (built using Umbraco backend) I get error :
Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request
The reason I have created my own controller and view , is to create product listing and shopping cart myself rather then using other off the shelves shopping carts.
My plan is to use Umbraco to create static pages like Home,Services , contact us etc so the company's admin team can easily amend/add new pages. But all other dynamic pages like user registration , cart, product and image management I would like to do it myself as I feel more comfortable coding in asp.net MVC. Is this the correct approach ?
At the moment I have just basic controller and View just for testing and learning:
Controller :
public class LoginController :Controller
{
// GET: Login
public ActionResult Index()
{
return View();
}
}
After route hijacking everything works fine but when I try to add :
Layout = "~/Views/Overflow.cshtml";
Layout created in Umbraco then I get the error. So If I want to use Layouts created in Umbraco what do I have to do ? or do I have to create separate layout for external pages (pages out side Umbraco).
Problem is that Umbraco is handling all request to your application.
If you want to use your own controllers and views you have to change routing .
As for me you don't need to create your own controller for Login page.
Just make Login page in Umbraco with Login View, in the Login View add your code and handle all request in your custom controller. You can use Surface or UmbracoApiController for handling requests, and there are no problems with Umbraco context.
Hi Alex,
So you recommend same approach for product listing and cart etc as well ?
I am new to Umbraco and still learning so thats why I am not sure and also please let me know what is the best resource to learn Umbraco.
It's easier to have all pages in Umbraco - you need only add your custom logic and handle all requests.
But If you really want to have no Umbraco context and pure MVC pages you can do it. I don't see sense in your case, maybe you can write why do you want it?
Hi Alex,
I am new to Umbraco so struggling a bit. Thats why I said I feel more confident if I use pure MVC.
I have some confusion , could you please help me so I can get my head around and clear the confusion.
I have a database of 3,000 mix products, up to 4 different product categories. To display products do I have to create two document type:
1. One document for showing all products with paging.
2. Second document for showing individual product (when use click on any product).
Is this the correct way ?
Sorry for asking such a basic questions.
If you have one document type for list and for one project - you need to check if there product id in request - if yes - show product view, if no - product list.
I would have 2 document types, it's better I think.
Layout Issue
Hi, I have added my own controller and views using visual studio in to existing Umbraco application. In my views if I try to use layout (built using Umbraco backend) I get error :
Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request
The layout contains Umbraco fields for example :
is there a way to resolve this issue or do I have to create a separate layout for my views.
Thanks
Hi Fahad,
If you want to use Umbraco.Field you have to be in Umbreaco context, these methods work on the Umbraco page.
What controller did you add ?
If you want to add logic to Umbraco handling request try to use RenderMvcController - https://our.umbraco.org/documentation/reference/routing/custom-controllers
Can you please provide code of your view and describe why did you decide to add your own controller and view?
Thanks,
Alex
Hi Alex,
The reason I have created my own controller and view , is to create product listing and shopping cart myself rather then using other off the shelves shopping carts. My plan is to use Umbraco to create static pages like Home,Services , contact us etc so the company's admin team can easily amend/add new pages. But all other dynamic pages like user registration , cart, product and image management I would like to do it myself as I feel more comfortable coding in asp.net MVC. Is this the correct approach ?
At the moment I have just basic controller and View just for testing and learning:
Controller :
View :
After route hijacking everything works fine but when I try to add :
Layout created in Umbraco then I get the error. So If I want to use Layouts created in Umbraco what do I have to do ? or do I have to create separate layout for external pages (pages out side Umbraco).
Thanks
Problem is that Umbraco is handling all request to your application.
If you want to use your own controllers and views you have to change routing .
As for me you don't need to create your own controller for Login page.
Just make Login page in Umbraco with Login View, in the Login View add your code and handle all request in your custom controller. You can use Surface or UmbracoApiController for handling requests, and there are no problems with Umbraco context.
Thanks,
Alex
Hi Alex, So you recommend same approach for product listing and cart etc as well ? I am new to Umbraco and still learning so thats why I am not sure and also please let me know what is the best resource to learn Umbraco.
Thanks
Hi Fahad,
It's easier to have all pages in Umbraco - you need only add your custom logic and handle all requests.
But If you really want to have no Umbraco context and pure MVC pages you can do it. I don't see sense in your case, maybe you can write why do you want it?
Thanks,
Alex
Hi Alex, I am new to Umbraco so struggling a bit. Thats why I said I feel more confident if I use pure MVC.
I have some confusion , could you please help me so I can get my head around and clear the confusion. I have a database of 3,000 mix products, up to 4 different product categories. To display products do I have to create two document type: 1. One document for showing all products with paging. 2. Second document for showing individual product (when use click on any product).
Is this the correct way ? Sorry for asking such a basic questions.
Thanks
Hi Fahad,
You can have 2 document types or one.
If you have one document type for list and for one project - you need to check if there product id in request - if yes - show product view, if no - product list.
I would have 2 document types, it's better I think.
Thanks,
Alex
I Umbraco will be one product page - /product
For each product you add id in request - /product/f3f3test - for example.
Get data from your database by product id.
Umbraco will be easy to maintain 1 product page, where you will store general product data.
Thanks,
Alex
Hi Fahad,
How are you? Did you solve the problem?
Thanks
is working on a reply...