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

  • SEARCH
  • Home
  • 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 648945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:53:19+00:00 2026-05-13T21:53:19+00:00

I am using ASP.NET MVC2 and Entity Framework. I am going to simplify the

  • 0

I am using ASP.NET MVC2 and Entity Framework. I am going to simplify the situation a little; hopefully it will make it clearer, not more confusing!

I have a controller action to create address, and the country is a lookup table (in other words, there is a one-to-many relationship between Country and Address classes). Let’s say for clarity that the field in the Address class is called Address.Land. And, for the purposes of the dropdown list, I am getting Country.CountryID and Country.Name.

I am aware of Model vs. Input validation. So, if I call the dropdown field formLand – I can make it work. But if I call the field Land (that is, matching the variable in Address class) – I am getting the following error:

“The parameter conversion from type
‘System.String’ to type ‘App.Country’
failed because no type converter can
convert between these types.”

OK, this makes sense. A string (CountryID) comes from the form and the binder doesn’t know how to convert it to Country type. So, I wrote the converter:

namespace App {
    public partial class Country {
        public static explicit operator Country(string countryID) {
            AppEntities context = new AppEntities();
            Country country = (Country) context.GetObjectByKey(
                new EntityKey("AppEntities.Countries", "CountryID", countryID));
            return country;
        }
    }
}

FWIW, I tried both explicit and implicit. I tested it from the controller – Country c = (Country)"fr" – and it works fine. However, it never got invoked when the View is posted. I am getting the same “no type converter” error in the model.

Any ideas how to hint to the model binder that there is a type converter?
Thanks

  • 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-13T21:53:19+00:00Added an answer on May 13, 2026 at 9:53 pm

    A type converter is not the same as an explicit or implicit conversion, it’s an object that converts values between various types.

    I think you need to create a class inherited from TypeConverter that converts between Country and other types, and apply the TypeConverterAttribute to your class to specify the converter to use :

    using System.ComponentModel;
    
    public class CountryConverter : TypeConverter
    {
        // override CanConvertTo, CanConvertFrom, ConvertTo and ConvertFrom
        // (not sure about other methods...)
    }
    
    [TypeConverter(typeof(CountryConverter))]
    public partial class Country
    {
    
    ...
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer XML is not a display format. It doesn't not "understand"… May 14, 2026 at 8:37 pm
  • Editorial Team
    Editorial Team added an answer If you want to find module definitions with a control,… May 14, 2026 at 8:37 pm
  • Editorial Team
    Editorial Team added an answer Your're close, but not quite there. For a secure hash,… May 14, 2026 at 8:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.