我试着写自定义模型活页夹,但它是一个错误,谁能告诉我在哪里做错了吗?
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Models
{
public class CustomModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
Ownership own = new Ownership();
own.name = controllerContext.HttpContext.Request.Form["fName"];
own.email = controllerContext.HttpContext.Request.Form["fEmail"];
own.PhoneNo = controllerContext.HttpContext.Request.Form["fPhoneNo"];
own.country = controllerContext.HttpContext.Request.Form["Country"];
own.address = controllerContext.HttpContext.Request.Form["Adres"];
own.office = controllerContext.HttpContext.Request.Form["Off"];
own.officeEmail = controllerContext.HttpContext.Request.Form["OffEmail"];
own.officeNo = controllerContext.HttpContext.Request.Form["OffNo"];
own.OwnershipType = controllerContext.HttpContext.Request.Form["OwnershipType"];
own.ProductId = controllerContext.HttpContext.Request.Form["ProductId"];
return own;
}
}
}错误
"'CustomModelBinder‘不实现接口成员CustomModelBinder System.Web.Mvc.ModelBindingContext)’
发布于 2014-10-10 13:25:28
您正在使用的System.Web.ModelBinding名称空间中的IModelBinder。此接口的BindModel方法返回bool类型的值。
bool BindModel(
ModelBindingExecutionContext modelBindingExecutionContext,
ModelBindingContext bindingContext
)如果要使用返回对象的BindModel方法,则需要实现来自BindModel命名空间的接口。
Object BindModel(
ControllerContext controllerContext,
ModelBindingContext bindingContext
)您可以通过在实现此IModelBinder接口时提供完整的命名空间来检查它。喜欢
public class CustomModelBinder : System.Web.Mvc.IModelBinder
{
public object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext)
{
Ownership own = new Ownership();
own.name = controllerContext.HttpContext.Request.Form["fName"];
own.email = controllerContext.HttpContext.Request.Form["fEmail"];
own.PhoneNo = controllerContext.HttpContext.Request.Form["fPhoneNo"];
own.country = controllerContext.HttpContext.Request.Form["Country"];
own.address = controllerContext.HttpContext.Request.Form["Adres"];
own.office = controllerContext.HttpContext.Request.Form["Off"];
own.officeEmail = controllerContext.HttpContext.Request.Form["OffEmail"];
own.officeNo = controllerContext.HttpContext.Request.Form["OffNo"];
own.OwnershipType = controllerContext.HttpContext.Request.Form["OwnershipType"];
own.ProductId = controllerContext.HttpContext.Request.Form["ProductId"];
return own;
}
}https://stackoverflow.com/questions/26298566
复制相似问题