Copied to clipboard

Flag this post as spam?

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


  • JVG 2 posts 22 karma points
    Aug 14, 2013 @ 12:35
    JVG
    0

    Real MVC Implementation - View does not depend on Umbraco implementations

    I have followed this nice tutorial which explains how you can take even more advantage of using Umbraco as a content delivery system. Tutorial MVC Umbraco => Your model and views should not depend on specific Umbraco implementations which is a huge advantage for real front-end developers.

    Controller:

     public class FrontPageController : MasterDocTypeController
    {
        public ActionResult FrontPage(RenderModel renderModel)
        {   
            FrontPageModel blobsList = renderModel.Content.Map();
            blobsList.FillBlobList(storageContainer.ListBlobs(useFlatBlobListing: true));
    
            return View(blobsList);
        }}
    

    View:

    View

    Model:

     public class FrontPageModel:MasterModel
    {
        public string Title { get; set; }
        public IHtmlString BodyText { get; set; }
        public string Answer { get; set; }
        public List<CloudFile> Files { get; set; }
    
        //CONSTRUCTOR
        public FrontPageModel()
            : this(null)
        {
            Files = new List<CloudFile>();
        }
    
        public FrontPageModel(IEnumerable<IListBlobItem> list)
        {
            FillList(list);
        }
    
        //METHODS
        public void FillBlobList(IEnumerable<IListBlobItem> list)
        {
            FillList(list);
        }
    }
    

    As you can see, most of the things are the same as in tutorial.

    When playing around, i faced an issue with the Actionlink in my view.

    <a href="">Upload Another File</a>
    

    The link doesn't work because the HREF value has not been populated. This link should redirect the page to the same Controller (FrontPage). It seems this is causing the problem, because it is working when redirecting to a "surfacecontroller" instead of "renderMVCcontroller".

    I feel that redirecting to other controller is breaking the normal MVC Structure. Is it right to say that one can not redirect to other pages when action is defined inside "rendermvccontroller"? How would you resolve this issue?

  • JVG 2 posts 22 karma points
    Aug 19, 2013 @ 10:04
    JVG
    0

    Extension to my first post => Should we really use surface controller when we have @HTML.ActionLink("Upload Another File,UploadFile,FrontPage") on our page ?

    Currently, when i want to retrieve data from the CMS itself, i'am using RenderMVCController which is giving a RenderModel as a argument in your constructor. When using this controller, how can you manage navigation between pages?

  • Nick Frederiksen 18 posts 77 karma points
    Sep 27, 2013 @ 23:19
    Nick Frederiksen
    0

    Hi,

     

    I'm the author of the post you've linked to.

    I don't know if you had your question answered, but for further reference:

    You cannot use Html.ActionLink, Url.Action or Ajax.ActionLink to link to a page. Why?

    First of, umbraco content is content, not actions. All requests are routed to the controllers and actions. Meaning content is delivered by parsing urls -> controller + action.

    To create a link to an other page, you must simply provide the url in your model like:

    model.LinkToSomePage = CurrentPage.Children.First().Url;

    Or whatever page you want to link to.

    Here's an answer that clearifies it a bit more: http://stackoverflow.com/a/18313882

     

    You can, however, use Html.ActionLink, Url.Action, Ajax.ActionLink, to get a URL to a surface controller action and/or API controller action. But not RenderMvcController actions.

    Hope that clearifies it for you.

Please Sign in or register to post replies

Write your reply to:

Draft