Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fahad Ayub 71 posts 238 karma points
    Jul 27, 2016 @ 07:55
    Fahad Ayub
    1

    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 :

    <title>@Umbraco.Field("pageName") | @Umbraco.Field("siteName", recursive: true)</title>
    

    is there a way to resolve this issue or do I have to create a separate layout for my views.

    Thanks

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2016 @ 12:12
    Alex Skrypnyk
    0

    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

  • Fahad Ayub 71 posts 238 karma points
    Jul 27, 2016 @ 13:08
    Fahad Ayub
    1

    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 :

    public class LoginController :Controller
        {
            // GET: Login
            public ActionResult Index()
            {
                return View();
            }
        }
    

    View :

    @{
    
        ViewBag.Title = "Index";
    }
    
    <h2>Login Page </h2>
    

    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).

    Thanks

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2016 @ 13:25
    Alex Skrypnyk
    0

    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

  • Fahad Ayub 71 posts 238 karma points
    Jul 27, 2016 @ 13:58
    Fahad Ayub
    0

    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

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2016 @ 14:33
    Alex Skrypnyk
    0

    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

  • Fahad Ayub 71 posts 238 karma points
    Jul 27, 2016 @ 15:15
    Fahad Ayub
    0

    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

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2016 @ 15:48
    Alex Skrypnyk
    0

    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

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 27, 2016 @ 15:49
    Alex Skrypnyk
    0

    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

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 28, 2016 @ 11:25
    Alex Skrypnyk
    0

    Hi Fahad,

    How are you? Did you solve the problem?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft