Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 770325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:28:54+00:00 2026-05-14T18:28:54+00:00

Hi I am using a custom model binder with asp.net mvc 2.0 , everything

  • 0

Hi I am using a custom model binder with asp.net mvc 2.0 , everything works locally but when deployed to the server runing iis 7, i get a weird error which is hard to get information about the error is as follows, I am also attaching my model binding class

Error:

[MissingMethodException: Method not found: 'System.Collections.Generic.IDictionary`2<System.String,System.Web.Mvc.ValueProviderResult> System.Web.Mvc.ModelBindingContext.get_ValueProvider()'.]
FID.Binders.documentModelBinder.GetValue(ModelBindingContext bindingContext, String key) in C:\Users\Bich Vu\Documents\Visual Studio 2010\Projects\FID\FID\Binders\DocumentModelBinder.cs:155
FID.Binders.documentModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) in C:\Users\Bich Vu\Documents\Visual Studio 2010\Projects\FID\FID\Binders\DocumentModelBinder.cs:61
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +475
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +152
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709
System.Web.Mvc.Controller.ExecuteCore() +162
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +58
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371  Below  is the code file

Code:

public class BinddocumentAttribute : DataBindAttribute
{
  public  BinddocumentAttribute() : base(typeof(documentModelBinder)) { }

  public class documentModelBinder : DefaultModelBinder
  {
    ICategoryService _CategoryService=   ServiceLocator.Current.GetInstance<ICategoryService>();
    IFilePersistor _persistor = ServiceLocator.Current.GetInstance<IFilePersistor>();
    IFileTypeService _FiletypeService = ServiceLocator.Current.GetInstance<IFileTypeService>();      

    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var doc = base.BindModel(controllerContext, bindingContext) as Document;

        string key = bindingContext.ModelName;

        var errors = Core.xval.DataAnnotationsValidationRunner.GetErrors(doc);

        try
        {
            if (errors.Any())
                throw new xVal.ServerSide.RulesException(errors);

          foreach (string inputTagName in controllerContext.HttpContext.Request.Files)
          {
            HttpPostedFileBase filebase = controllerContext.HttpContext.Request.Files[inputTagName];
            if (filebase.ContentLength==0)
                 break; 
            string  extension= Path.GetExtension(filebase.FileName);

            if (!filebase.ContentType.Contains("image/"))
            {
              if (extension != _FiletypeService.GetFiletype(GetValue<short>(bindingContext, "Filetype_id")).extension.Trim())
              {
                bindingContext.ModelState.AddModelError("filetype", "Verify that the file type matches the selected file type");                           
                throw new RulesException("filetype", "Verify that the file type matches the selected file type", doc);

              }
            }
          }
        }
        catch (xVal.ServerSide.RulesException ex)
        {
            return null;
        }

        doc.Category1 = _CategoryService.GetCategory(GetValue<int>(bindingContext, "cat.parent_id"));
        doc.FileType1 = _FiletypeService.GetFiletype(GetValue<short>(bindingContext, "Filetype_id"));
        doc.modifieddate = DateTime.Now;

        if (doc.IsNewDocument)
        {
            doc.CreateParentFolders();
            doc.createdate = DateTime.Now;
        }

        UpdateFiles(controllerContext, doc);
        return doc;
    }

    private void UpdateFiles(ControllerContext controllerContext, Document doc)
    {
      foreach (string inputTagName in controllerContext.HttpContext.Request.Files)
      {
        HttpPostedFileBase filebase = controllerContext.HttpContext.Request.Files[inputTagName];
        if (filebase.ContentLength > 0)
        {
          if (filebase.ContentType.Contains("image/"))
          {
            Thumb image = new Thumb { type = filebase.ContentType, name = filebase.FileName, PostedFile = filebase, AssociatedDocument = doc, document_id=doc.document_id };
            image.filepath = _persistor.PersistFile(image);
            doc.Thumbs.Add(image);
          }
          else
          {
            doc.PostedFile = filebase;
            doc.filesize = long.Parse(filebase.ContentLength.ToString());
            doc.filepath = _persistor.PersistFile(doc);
          }
        }
      }
    }

    private T GetValue<T>(ModelBindingContext bindingContext, string key)
    {
        ValueProviderResult valueResult;
        bindingContext.ValueProvider.TryGetValue(key, out valueResult);
        bindingContext.ModelState.SetModelValue(key, valueResult);
        return (T)valueResult.ConvertTo(typeof(T));
    }

    protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var document = bindingContext.Model as Document;
        if (String.IsNullOrEmpty(document.title))
        {
            bindingContext.ModelState.AddModelError("Name", "...");
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:28:55+00:00Added an answer on May 14, 2026 at 6:28 pm

    First you should make sure your running the correct assemblies

    Second
    In MVC2 the following is not valid. The IValueProvider Interface has changed

    bindingContext.ValueProvider.TryGetValue(key, out valueResult); 
    

    should be replaced with

    valueResult = bindingContext.ValueProvider.GetValue(key); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.