Copied to clipboard

Flag this post as spam?

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


  • Khai 71 posts 161 karma points
    Apr 25, 2013 @ 16:58
    Khai
    0

    Umbraco MVC? Confused how to use the controller

    So I'm working on a MVC umbraco project however I'm quite confused how to use MVC in the right way in Umbraco with controllers. For example, I'm building a newsmodule. So I create a document type "NewsItem" in Umbraco with a view as template. I have a news overview page, which shows newsitems with pagination. I could write the news overview as a partial view but then the partial view would have too much logic in it. So what I did:

    1. I created a news page ( document type content page )
    2. I created a newscontroller with an actionresult method "index" which has a querystring as parameter.
    3. I created a News Model, In the controller I map the newsitem document to the news model.
    4. The index method returns a view with a list of newsitem as model.
    5. I create a macropartial which only includes the call to the controller. ( @Html.Action("Index", "News", new { query = Request.QueryString["index"]} )
    6. I add the macropartial to the news page. ( and it will call the controller with the querystring and render the action result of the controller. )
    It works, but I'm not sure if I'm doing it the correct way.. What also bothers me is that you usally have a detail method in a controller which returns a view with one newsitem as model. But I already have a detailpage for the newsitem because the document type "NewsItem" has a template. I tried to implement this anyways, just to see if it works. So I created the method and tried to return a view which has a master view. However I get an error saying that the Model is not valid.. And whenever I delete the master view from the detail view it works again. So I probably get this error because the master view expects an IPublishedContent model but I give the detail view a NewsItem model.
    So I'm hoping someone can provide me with info how to work with MVC in umbraco.. cause I'm not able to find any good tutorials with MVC and I have the idea that I'm not working in the correct way with MVC.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies