Copied to clipboard

Flag this post as spam?

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


  • Tom C 87 posts 222 karma points
    Jun 05, 2015 @ 21:24
    Tom C
    0

    Quick mvc routing question

    Hopefully this might be a simple quesiton for someone who understands MVC well,

    I have a page and in it I want to have a link to a dynamically generated image served from the page's controller,

    ie so if my page is located at http://mysite/ExamplePage

    in the html I want a link like this

    <img src="/ExamplePage/MyImageAction"/>

    and I thought having a Controller like this

    ---

      public class ExamplePageController : RenderMvcController

        {

            public ActionResult MyImageAction(Umbraco.Web.Models.RenderModel model)

            {}

    --

    would do the trick, but it doesn't, ie my idea of the link to it isn't recognised by Umbraco. I have some research but I am still not well versed in MVC .. do i need to map a custom route for this, or is there another way of calling my Controller Action?

    Thank-you to anyone who can help me here.

     

     

  • James Jackson-South 489 posts 1747 karma points c-trib
    Jun 07, 2015 @ 15:45
    James Jackson-South
    0

    Hi Tom,

    An ActionResult really wouldn't be the best place for returning a dynamic image in this manner. Scott Hanselman demonstrates an approach to producing dynamic images using controllers and a custom result but if you read the comments in the article you'll see that it is not a great idea.

    Umbraco 7 actually comes with ImageProcessor built in to the core which will allow you to create images with a lot of options.

    http://imageprocessor.org/imageprocessor-web/

    You can create the images by utilising the url api. You get the advantage of highly tuned caching and memory management.

    If what you need is not already built into ImageProcessor then you can easily enough extend the library with your own processor.

    http://imageprocessor.org/imageprocessor-web/extending/#iwebgraphicsprocessor

    There's tons of examples in the source on Github. If you get stuck just ask here on the forum and I will happily give you a hand. (I wrote it so I'm probably the best person to ask).

    Best of luck

    James

  • Tom C 87 posts 222 karma points
    Jun 09, 2015 @ 18:07
    Tom C
    0

    Thanks for your reply .. actually the image generating bit was working ok, it was just the MVC I was struggling with. I couldn't figure it out, so in the end I cmae up with the idea of overriding the controller Index method and checking for a query string parameter which if present would generate the image, and if not, just show the page as normal. 

Please Sign in or register to post replies

Write your reply to:

Draft