Orchard CMS渲染部分在管理部分之外

时间:2011-07-01 00:08:36

标签: asp.net-mvc-3 module content-management-system orchardcms

我按照http://orchardproject.net/docs/Creating-a-module-with-a-simple-text-editor.ashx

中的说明处理模块

我想要做的一件事就是在管理模块之外创建产品。所以我创建了这样的家庭控制器

public class HomeController : Controller
{

    public HomeController(IContentManager cm) {
        ContentManager = cm;
    }

    private IContentManager ContentManager { get; set; }



 public ActionResult Index() {
        return Content("This is index");

    }        [Themed]
    public ActionResult Create()
    {
        var product = ContentManager.New("Product");
        var model = ContentManager.BuildEditor(product);
        return View((object) model);

    }

和根文件夹中的文件routes.cs

public class Routes : IRouteProvider
{
    public void GetRoutes(ICollection<RouteDescriptor> routes)
    {
        foreach (var routeDescriptor in GetRoutes())
            routes.Add(routeDescriptor);
    }

    public IEnumerable<RouteDescriptor> GetRoutes()
    {
        return new[] {
            new RouteDescriptor {
                Priority = 5,
                Route = new Route(
                    "commerce",
                    new RouteValueDictionary {
                        {"area", "SimpleCommerce"},
                        {"controller", "Home"},
                        {"action", "Index"}
                    },
                    new RouteValueDictionary(),
                    new RouteValueDictionary {
                        {"area", "SimpleCommerce"}
                    },
                    new MvcRouteHandler())
            },
            new RouteDescriptor {
                Priority = 6,
                Route = new Route(
                    "commerce/Create",
                    new RouteValueDictionary {
                        {"area", "SimpleCommerce"},
                        {"controller", "Home"},
                        {"action", "Create"}
                    },
                    new RouteValueDictionary(),
                    new RouteValueDictionary {
                        {"area", "SimpleCommerce"}
                    },
                    new MvcRouteHandler())
            }

        };
    }
}

因此,当我导航到网址http://localhost:35713/commerce/create

时,我应该如何从此处开始将整个事物渲染到一起

但它抛出一个错误,说创建视图没有找到。然后我在Views / Home文件夹

中创建了一个视图(create.cshtml)
@model SimpleCommerce.Models.ProductPart
<fieldset>
    <label class="sub" for="Sku">@T("Sku")</label><br />
    @Html.TextBoxFor(m => m.Sku, new { @class = "text" })<br />
    <label class="sub" for="Price">@T("Price")</label><br />
    @Html.TextBoxFor(m => m.Price, new { @class = "text" })
</fieldset>

现在它抛出错误说

  

传递到字典中的模型项的类型为“IShapeProxyedcfa08c61cf49898dc2e77bde025039”,但此字典需要“SimpleCommerce.Models.ProductPart”类型的模型项。

1 个答案:

答案 0 :(得分:1)

哦,那是交叉发布的。 BuildEditor正在创建一个形状,您的模板期望一个强类型模型。删除@Model指令应该将该问题替换为另一个(这将导致您无法使用具有形状的基于Lambda的帮助程序。