locked
The model item passed into the dictionary is of type 'FabricRequest', but this dictionary requires a model item of type 'UserModel' RRS feed

  • Question

  • User2028040492 posted

    The model item passed into the dictionary is of type 'WFXImportTool.Models.FabricRequest' (in home area), but this dictionary requires a model item of type 'WFXImportTool.Models.UserModel'.

    I have an issue like this. I do not know how this always return "WFXImportTool.Models.UserModel" (this model belong to Admin area).

    I have this view:

    @model WFXImportTool.Models.FabricRequest
    @{
        ViewBag.Title = "WFXFabricRequest";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header bg-danger text-center text-light">
                    <h4 class="text-uppercase">Fabric Request</h4>
                </div>
                <div class="card-body">
                    @using (Html.BeginForm("FabricRequest", "WFXImportTool", FormMethod.Post))
                    {
                        <div class="form-row mb-3">
                            <div class="col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(m => m.ArticleName, "Article Name", new { @class = "bmd-label-floating" })
                                    @Html.TextBoxFor(m => m.ArticleName, Model.ArticleName, new { @class = "form-control" })
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="bmd-label-floating text-danger font-weight-bold">ProductGroup</label>
                                    @Html.DropDownListFor(m => m.ProductGroup, new SelectList(Model.ProductGroupModels, "ID", "ProductGroup"), "-- Select ProductGroup --", new { @class = "js-searchBox", @style = "overflow-y:visible; width: 100%;", @id = "cbbProductGroup", @name = "cbbProductGroup" })
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="bmd-label-floating text-danger font-weight-bold">Catalog Path</label>
                                    @Html.DropDownListFor(m => m.CatalogPath, new SelectList(Model.CatalogPathModels, "ID", "Title"), "-- Select Catalog Path --", new { @class = "js-searchBox", @style = "overflow-y:visible; width: 100%;", @id = "cbbCatalogPath", @name = "cbbCatalogPath" })
                                </div>
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>

    And this is my controller:

    #region GetData
    public void GetProductGroup(FabricRequest fabricRequest, string ProductCatCode)
    {
       Dictionary<string, object> param = new Dictionary<string, object>();
       param.Add("ProductCatCode", ProductCatCode);
       fabricRequest.ProductGroupModels = new List<ProductGroupModel>();
       fabricRequest.ProductGroupModels = DatabaseServer.ConvertDataTable<ProductGroupModel>(
                                          DatabaseServer.Read_Table("WFX_GetProductGroup", true, param));
    }
    public void GetCatalogPath(FabricRequest fabricRequest, string ProductCatCode)
    {
       Dictionary<string, object> param = new Dictionary<string, object>();
       param.Add("ProductCatCode", ProductCatCode);
       fabricRequest.CatalogPathModels = new List<CatalogPathModel>();
       fabricRequest.CatalogPathModels = DatabaseServer.ConvertDataTable<CatalogPathModel>(
                                         DatabaseServer.Read_Table("WFX_GetCatalogPath", true, param));
    }
    #endregion
    
    #region WFX FabricRequset
    public ActionResult WFXFabricRequest()
    {
       FabricRequest fabricRequest = new FabricRequest();
       GetCatalogPath(fabricRequest, "03");
       GetProductGroup(fabricRequest, "03");
       return View(fabricRequest);
    }
    #endregion

    Monday, May 18, 2020 1:18 AM

All replies

  • User475983607 posted

    I have an issue like this. I do not know how this always return "WFXImportTool.Models.UserModel" (this model belong to Admin area).

    Most likely you are not editing the View found in the Admin Area.  Or you did not add the View.  Or you forgot the to add the Admin area to a controller.   You'll need to go through your code and make sure you properly configured Areas.

    Monday, May 18, 2020 11:03 AM
  • User1686398519 posted

    Hi,  DuyKhuong

    DatabaseServer.ConvertDataTable<ProductGroupModel>(
                                          DatabaseServer.Read_Table("WFX_GetProductGroup", true, param));

    I want to confirm with you whether this method is a custom method.After I comment it, the page will not report an error, can you give more detailed code?

    Best Regards,

    YihuiSun

    Tuesday, May 19, 2020 3:12 AM