Copied to clipboard

Flag this post as spam?

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


  • Peter Jensen 32 posts 137 karma points
    Nov 13, 2012 @ 13:28
    Peter Jensen
    0

    How to render the correct link for action in 4.10

    Hey all 

    dahm the new mvc version is sweet really like it, but i encountered a minor problem :) I want to make some files a valible for download on the page but i want to force download em. 

    so i made a controller like this:

    public class DownloadController : Umbraco.Web.Mvc.SurfaceController
        {
    
            public ActionResult ForceDownload()
            {
                var filePath = Umbraco.TypedMedia(id).GetProperty("umbracoFile").Value.ToString();
    
                Response.AddHeader("Content-Disposition", "attachment;filename=dealers.png");
                Response.WriteFile(filePath);
                //Response.ContentType = "";
                Response.End();
                return null;
    
            }
    
        }

    But i cant seem to invoke th action i created from my view. trying this method.

    @Html.Action("ForceDownload", "Download");

    Any help would be lovely  :) 

     

  • Peter Jensen 32 posts 137 karma points
    Nov 13, 2012 @ 13:41
    Peter Jensen
    100

    if i try @Html.ActionLink("ForceDownload", "Download");

    if get this error : 

    There is not current PublishedContentRequest, it must be initialized before the RenderRouteHandler executes

  • Richard Terris 273 posts 715 karma points
    Nov 27, 2012 @ 10:41
    Richard Terris
    1

    Hi Peter

    I think the controller name has to be suffixed with Surface, so I'd  rename the .cs file to DownloadSurfaceController and ensure that change is cascaded down into the code

     

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft