我收到以下错误传递到字典的模型项的类型为“MvcWebApplication.Models.Product”,但此字典需要“MvcWebApplication.ViewModels.ProductCommonViewModel”类型的模型项。
控制器代码如下:-
public ActionResult Index([Bind(Prefix= "MvcWebApplication.ViewModels.ProductCommonViewModel")] Product product)
View Model class sent to the View:
namespace MvcWebApplication.ViewModels
{
public class ProductCommonViewModel
{
public Product Product { get; set; }
}
}
模型粘合剂:
namespace MvcWebApplication.ModelBinders
{
public class ProductBinder : IModelBinder
{
#region IModelBinder Members
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
HttpRequestBase fc = controllerContext.HttpContext.Request;
Product product = new Product();
LaunchSheet launchSheet = null; ;
ProductPricing productPricing = null;
product.LoanTypeId = Convert.ToInt32(fc["rblLoanType"]);
product.ProductTypeId = Convert.ToInt32(fc["ddlproductType"]);
etc...
return Product;
}
}
}
产品类别
[ModelBinder(typeof(ProductBinder))]
public partial class Product : IRuleEntity
{
}
我究竟做错了什么?