razorumbracoumbraco5

Umbraco 5 surface controller and partial macro


I'm playing with Umbraco 5 (complete newbie) and currently trying to experiment with the surface controller and macro's.

I've created a basic surface controller:

public class TestSurfaceController : SurfaceController
{
    //
    // GET: /TestSurface/

    [ChildActionOnly]
    public ActionResult GetTest()
    {
        List<Test> test = new List<Test>();
        test.Add(new Test { TestTitle = "Test" });

        return View(test);
    }

}

And a partial macro:

@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework

@model IEnumerable<Umbraco.Models.Test>

<ul>
  @foreach (var test in Model)
  {
    <li>@test.TestTitle</li>
  }
</ul>

And on my home template, I call it:

@inherits RenderViewPage
@using System.Web.Mvc.Html;
@using Umbraco.Cms.Web;
@{
Layout = "_Layout.cshtml";
 }

@section head
{
@Umbraco.RenderMacro("getTest")
}

How do I get it to just display test in the ul? I either get an error saying I can't use inherits if model is used, then if I take away inherits I get a message saying that the model supplied isn't as expected.


Solution

  • @inherits RenderViewPage Remove this line from your partial page, if you want i can post an example of a working surface controller action and partial view. hope that helps. Working Example is below,

    public class MDSSurfaceController : SurfaceController
    {        
        public MDSSurfaceController(IRoutableRequestContext routableRequestContext)
            : base(routableRequestContext)
        {
        }
        [ChildActionOnly]
        public PartialViewResult ApartmentListMacro(string apartmentType, string Name, string PropertyRfDicItem, string RatesperNightDict, string SleepsDict, string BedroomsDict, string BathroomsDict, string ViewDict)
        {
            ApartmentListModel apM = new ApartmentListModel();
            //initialize model           
            return PartialView(apM);
        }
    

    Then my Partial View is

    @using Umbraco.Cms.Packages.SystemInfo.Models
    @model Umbraco.Cms.Packages.SystemInfo.Models.ApartmentListModel
    @{
    //Html Code
    }