English 中文(简体)
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.

最佳回答

@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
}
问题回答

暂无回答




相关问题
Creating custom content sections with umbraco

I m working on an umbraco website just now and one of the requirements is to have a custom section in the back end that can be used to manage publish smaller micro-sites. I have been able to create ...

MVC and Umbraco integration

I ve followed the steps from http://memoryleak.me.uk/2009/04/umbraco-and-aspnet-mvc.html and integrated MVC in Umbraco with success, but I still have a problem which is critical for me. Is there any ...

Umbraco server error after install

I downloaded umbraco and used the web platform installer. Everything went though okay and it installed SQL Express 2008 and a new directory under the default website in IIS. However when I launch the ...

XSLT, sort and group by year-date

Regarding Umbraco XSLT version 1. I have aprox. 150 news items in XML. Lets say like this (all is pseudocode until I get more familiar with this xml/xslt): <news> <data alias=date>2008-...

Open node in Umbraco programmatically

I have created a dashboard for an Umbraco site and I want to link from it to various node in the tree. From what I can tell Umbraco uses editcontent.aspx?id={thenodeid} and javascript:opencontent({...

Umbraco Back Office Membership Provider

Has anyone had any experience trying to write a custom Membership Provider for the Umbraco back office? I ve run into all sorts of trouble trying to make this happen. You can see some more details ...

热门标签