1
votes

I am working on a module by following the instructions here http://orchardproject.net/docs/Creating-a-module-with-a-simple-text-editor.ashx

The one change I want to do is, rendering the product creation outside of admin module. So I created homecontroller like this

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);

    }

and a file routes.cs in the root folder

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())
            }

        };
    }
}

So how should I move from here onwards to render this whole thing together when I navigate to url http://localhost:35713/commerce/create

But it throws an error saying create view didnt find. Then I created a view (create.cshtml) in Views/Home folder

@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>

Now it throws an error saying

The model item passed into the dictionary is of type 'IShapeProxyedcfa08c61cf49898dc2e77bde025039', but this dictionary requires a model item of type 'SimpleCommerce.Models.ProductPart'.

1

1 Answers

1
votes

Oh, that's cross-posted. BuildEditor is creating a shape, and your template is expecting a strongly-typed model. Dropping the @Model directive should substitute that problem with another (which is that you won't be able to use the Lambda-based helpers with shapes.