Copied to clipboard

Flag this post as spam?

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


  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Jan 14, 2015 @ 15:55
    Rasmus Fjord
    0

    How to redirect from either a surface or api controller after file upload

    Hey there 

    Ive created an API controller that i can upload files through which is great. Since we dont have full browser support on sending multipart form data over ajax im just doing a good old fashion form submit to an API controller. This works, i get my files uploaded and all is green. But how can i redirect a user after this from an API controller ? 

    And my thought was if I should use a surface controller since an api isnt supposed to redirect, but i Cannot hit my surface controller through my post. And im probably doing it wrong :) 

    My attempt is that i have created some like this : 

     public class UploadController : SurfaceController
        {
            [System.Web.Http.HttpPost]
            public ActionResult CurrentMemberImage(HttpRequestMessage Image)
            {

    Then i have added it to my route table like this(because that is how i control my api controller paths) :

         RouteTable.Routes.MapHttpRoute("UploadMemberImageApi", "Api/UploadMemberImage", new { controller = "Upload", action = "CurrentMemberImage" });
           

    This just returns a "upload  controller not found" thingy.

    First of all if I could redirect through my API controller i would prefer it since everything else is made with them.

     

    Please tutor me ;)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 14, 2015 @ 16:43
    Dennis Aaen
    1

    Hi Rasmus,

    DonĀ“t know if this can be at any help, but here is an example of how to redirect after some has logged in, perhaps you can benefit from this to do your redirect after the file has been uploaded.

    http://24days.in/umbraco/2012/creating-a-login-form-with-umbraco-mvc-surfacecontroller/

    Hope this can help you further.

    /Dennis

  • Steve Morgan 1348 posts 4457 karma points c-trib
    Jan 14, 2015 @ 16:45
    Steve Morgan
    1

    Rasmus,

    Your first problem is the class name. it has to be XXXXSurfaceController e.g. UploadSurfaceController, though you've correctly inherited the base class the name is still important (due to Umbraco routing I think). 

    As Denis says follow that tutorial!

    Steve

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Jan 14, 2015 @ 19:58
    Rasmus Fjord
    0

    OH

    Thought that it was like the API thing so it would just be named "controller" ill fix that and try again :) 

  • Rasmus Fjord 675 posts 1566 karma points c-trib
    Jan 15, 2015 @ 09:08
    Rasmus Fjord
    100

    Okay my solution was like this, i kept using the API controller and figured out that i could redirect after a finished like this :

     [HttpPost]
            public void CurrentMemberImage(HttpRequestMessage Image)
            {
                var service = ApplicationContext.Current.Services.MemberService;
                var currentmember = service.GetById(Members.GetCurrentMember().Id);
    
                //DO STUFF HERE
    
                var response = HttpContext.Current.Response;
                response.Redirect("/");
    
            }
Please Sign in or register to post replies

Write your reply to:

Draft