Copied to clipboard

Flag this post as spam?

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


  • Adrian 3 posts 23 karma points
    Feb 05, 2014 @ 06:46
    Adrian
    0

    CurrentPage is null on AJAX Postback

    Hey, I have drag and drop functionality hooked up in a view which posts back the file to a surface controller.

    Problem is once the razor files try to get the CurrentPage on postback the CurrentPage is always null.

    Any ideas how can get the CurrentPage? And hard coding the CurrentPage wont work cause there are a couple of razor files which load

    This is the razor file:

    @inherits UmbracoTemplatePage
                  @using WebApplication2.umbraco.Surface
        @{
        Layout = "umbLayout.cshtml";
    
        // If the editor has not explicitly provided the "Page title" property page 
        // then just show the name of the page otherwise show the provided title
    
        var pageTitle = string.IsNullOrWhiteSpace(CurrentPage.Title)
            ? CurrentPage.Name
            : CurrentPage.Title;    
        }
        <link href="~/css/dropzone.css" rel="stylesheet" />
        <div>
            @using (Html.BeginUmbracoForm<ConvertSurfaceController>("Convert", FormMethod.Post, new
        {
            enctype = "multipart/form-data",
            id = "uploadDemo",
            @class = "dropzone"
        }))
            {
                <div class="fallback row-fluid">
                    <input name="file" type="file" multiple />
                    <input type="submit" value="Upload" />
                </div>
            }
    </div>
    <script src="~/js/dropzone.js"></script>
    <script type="text/javascript">
        // "uploadDemo" is the camelized version of the HTML form's ID
        Dropzone.options.uploadDemo = {
            paramName: "file", // Must match the name of the HttpPostedFileBase argument that the Upload action expects.
            maxFileSize: 100 //MB
        };
    </script>
    

    Here is the controller:

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using System.Web.Mvc;
    
        namespace WebApplication2.umbraco.Surface
        {
        public class ConvertSurfaceController: Umbraco.Web.Mvc.SurfaceController
        {
        public ActionResult Index() 
        {
        return Content("hello world");
        }
                [HttpGet]
        public ActionResult Convert()
        {
            return View();
        }
    
        [HttpPost]
                public ActionResult Convert(HttpPostedFileBase file)
        {
            //TODO Handle the uploaded file here
            return View();
        }
    }
    }
    

    Any help would be great thanks!!

    Adrian

  • Tom 713 posts 954 karma points
    Mar 07, 2014 @ 01:54
    Tom
    0

    Hi Adrian,

    I have the same issue just wondering if you'd happened to find a way around it?

  • Matt Linsenbardt 24 posts 147 karma points
    Mar 07, 2014 @ 20:22
    Matt Linsenbardt
    0

    There is no CurrentPage available because you're not on a page, your calling back to a SurfaceController.

    You could pass in the current Node Id with the AJAX post and then use Umbraco.TypedContent to get the respective content.

    http://our.umbraco.org/forum/developers/razor/41775-Getting-IPublishedContent-in-SurfaceController

    Thanks,
    Matt

     

     

Please Sign in or register to post replies

Write your reply to:

Draft