Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sylvester 6 posts 87 karma points
    Apr 15, 2016 @ 12:45
    Sylvester
    0

    Display external db values in Umbraco solution. both as Partial view and as a Umbraco page.

    Hi,

    I am implementing a umbraco site which has to display category and its product from the another mvc solution. I have taken the values from mvc project

    Using SurfaceController I have taken the category names and displayed as Partial View (not sure if it is correct).

    Now If i click the particular category it should load a list of products under it. Here I am getting error like "Cannot bind source type Seab.Umbraco.Model.CategoryDetailModel to model type Umbraco.Web.Models.RenderModel."

    umbraco template page(hometemplate.cshtml)

    hometemplate.cshtml code :

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    ...
    some code for the template elements
    ...
    
    @Html.Action("CategoryMenu", "CategoryMenuSurface")
    

    CategoryMenu.cshtml code:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Seab.Umbraco.Model.ParentCategoryModel>
    
        @{
            foreach (var category in Model.ParentCategoryList)
            {
                <div class="col-xs-6 col-md-4 col-lg-4 levelone">
                    <div class="oddmenu">
                        @Url.Action("Index", "CategoryMenuSurface", new { id = category.Id })                    
                    </div>
                </div>
            }
        }
    

    categoryDetails.cshtml code :

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Seab.Umbraco.Model.CategoryDetailModel>
    
    @{
    
    ViewBag.Title = "CategoryDetails";
        Layout = "~/Views/Master.cshtml";
    }
    <h6>@Model.Id</h6>
    <h6>@Model.Name</h6>
    

    MyController code :

    public class CategoryMenuSurfaceController : SurfaceController
        {    
    
            public ActionResult CategoryMenu()
            {
                CategoryViewModelRepository categoryRepo = new CategoryViewModelRepository();
                var model = new ParentCategoryModel();
                model.ParentCategoryList = categoryRepo.GetParentCategoryList();
                return PartialView("CategoryMenu",model);
            }
            public ActionResult Index(int id)
            {
                CategoryViewModelRepository categoryRepo = new CategoryViewModelRepository();
                var model = new CategoryDetailModel();
                var category = categoryRepo.GetCategoryById(id);
                if (category != null)
                {
                    model.Id = category.Id;
                    model.Name = category.ParentName;
                }
    
                return PartialView("CategoryDetails", model);
    
            }
        }
    

    if someone give some sample code it would be great.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies