module not working in home controller

Topics: Customizing Orchard, General, Troubleshooting, Writing modules
Jul 1, 2011 at 12:51 AM

Hi Experts,

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

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.Routes;

namespace SimpleCommerce {
    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'.

If someone can help. It will be greatly appreciated.

 

Regards

Parminder

 

Coordinator
Jul 1, 2011 at 12:57 AM

Don't specify the model on your view: the model that is getting passed in is the shape you created when you called BuildEditor, not the part.

Jul 1, 2011 at 1:21 AM

hi bertrandleroy,

thanks a lot, but can you elaborate bit more. If I dont specify the model on the view it wont render the textbox and throws an error.

Regards

Parminder