Copied to clipboard

Flag this post as spam?

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


  • John Churchley 272 posts 1258 karma points c-trib
    Feb 03, 2015 @ 12:43
    John Churchley
    0

    Return partial view on with Actionlink

    I trying to load a partial view when an actionlink is click. I've attempted it by creating a surface controller however it's linking to the partialview rather than loading the partialview with the page. Creates a link to umbraco/Surface/ControllerName/Index

    Main View

    @Html.ActionLink("Index", "ControllerNameSurface")

    Controller

    public class ContollerNameSurfaceController : Umbraco.Web.Mvc.SurfaceController
    {
            public PartialViewResult Index()
            {
                return PartialView("Index");
            }
        }

    View /ContollerName/Index.cshtml

    @{
        Layout = null;
    }

    Hello

  • Damian Green 452 posts 1433 karma points
    Feb 03, 2015 @ 13:20
    Damian Green
    2

    Hi John,

    If you want to control the rendering for a page then you need to use route hijacking.

    So say you have an Index page like above:

    Create a document type called Index Create a content page of type Index

    Create a controller call IndexController and inherit from RenderMvcController

    The the action result is called the same as the template alias

    Do you stuff in there and then return view("");

    e.g.:

    public class IndexController : RenderMvcController
    {
        /// <summary>
        /// Hijack the Index Document Type Rendering
        /// </summary>
        /// <returns></returns>
    
        public ActionResult IndexTemplateAlias(string querystringval)
        {            
            // Do your stuff
            return View();
        }
    }
    

    Is that what you are after?

    Damian

  • John Churchley 272 posts 1258 karma points c-trib
    Feb 03, 2015 @ 13:28
    John Churchley
    0

    Hi Damian thanks for your reply I don't belive it's what I'm after. I'm trying to limit the page size but give the user the option to see a larger page alittle like "more posts" on twitter. I was just trying to get the partial view to display if they clicked on a link. I now attempting to get "Hello" (data) through JSON instead.

  • Damian Green 452 posts 1433 karma points
    Feb 03, 2015 @ 13:48
    Damian Green
    0

    Then your best bet would be an ajax request and you populate a div with the html returned from the partial - so you dont change pages.

    At the moment the request is returning the partial as the page which has no master page etc. so thats what you get - just the partial.

    Damian

  • Damian Green 452 posts 1433 karma points
    Feb 03, 2015 @ 13:49
    Damian Green
    1

    This article is a good example of the request but its using alt templates here.

    http://24days.in/umbraco/2012/ajax-paging-using-alttemplates/

    Damian

  • John Churchley 272 posts 1258 karma points c-trib
    Feb 03, 2015 @ 13:53
    John Churchley
    0

    Thanks Damian getting to be along the right lines what I'm after hopefully I can get this to work in MVC :)

  • Damian Green 452 posts 1433 karma points
    Feb 03, 2015 @ 15:04
    Damian Green
    1

    Best way to get it to work with MVC and Umbraco is to use an Umbraco Api Controller and return JSON.

    This page has some info in it:

    http://www.nibble.be/?p=224

    Damian

  • John Churchley 272 posts 1258 karma points c-trib
    Feb 04, 2015 @ 12:41
    John Churchley
    100

    Hi Damian,

    Thanks for all your help.

    I ended up creating an helper class to get the property

    public class JSONHelper
        {
            public string GetJSON(int pageID, string propertyName)
            {
                var storepage = UmbracoContext.Current.ContentCache.GetById(pageID);
                string JSONValue = storepage.GetPropertyValue(propertyName);
                return JSONValue;
            }
    }

    Then a SurfaceContoller 

    public ActionResult Index()
    {
                JSONHelper a = new JSONHelper();
                string jsonvalue = a.GetJSON(1100, "staffList").ToString(); 
                return Json(jsonvalue, JsonRequestBehavior.AllowGet);
    }
  • Willem Luijk 24 posts 95 karma points
    Aug 29, 2015 @ 08:10
    Willem Luijk
    0

    Hi Damian,

    How to connect in the index view the links from the buttons on the index page to another action in the same controller, these ones:

    @Html.ActionLink("Edit", "Edit", new { id = item.AnimalID })

    @Html.ActionLink("Details", "Details", new { id = item.AnimalID })

    @Html.ActionLink("Delete", "Delete", new { id = item.AnimalID })

Please Sign in or register to post replies

Write your reply to:

Draft