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 7767587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:42:52+00:00 2026-06-01T15:42:52+00:00

I have the following in my model: public sealed class OAuthProvider { private readonly

  • 0

I have the following in my model:

public sealed class OAuthProvider
{
    private readonly string name;

    private const string SOME_PROVIDER = "SOMEPROVIDER";
    public static readonly OAuthProvider SomeProvider = new OAuthProvider(SOME_PROVIDER);

    private OAuthProvider(String name) { this.name = name; }
    public override String ToString(){ return name; }
    public static implicit operator string(OAuthProvider oAuthProvider)
    {
        return oAuthProvider.name;
    }
    public static implicit operator OAuthProvider(string oAuthProvider)
    {
        switch (oAuthProvider)
        {
            case SOME_PROVIDER : return SomeProvider ;
            default: return null;
        }
    }
}

And this in my OAuth controller:

public ActionResult Profile(OAuthProvider network)
{...}

And this in my view:

@model SomeModel
Html.RenderAction("Profile", "OAuth", new { network = Model.Network });

Where Model.Network is a string

When this view is rendered, I can see (via breakpoint) that Model.Network is coming in as a string that isn’t null. My Profile(OAuthProvider) is being called but network is coming in as null despite the implicit type conversion being in place.

Am I going about this the wrong way? Am I forced to do an explicit cast?

  • 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-06-01T15:42:53+00:00Added an answer on June 1, 2026 at 3:42 pm

    Not sure if this might work, it’s not a direct answer to what you have (but it’s hard to say w/o debugging in similar cases) but might help (and is much text for the comment)…

    in similar cases when the binding doesn’t work as expected, often helps to debug – and that by making a custom binder.

    In your Application_Start you do something like this…

    ModelBinders.Binders.Add(typeof(YourNamespace.OAuthProvider), new YourNamespace.Binders.OAuthProviderClassBinder());
    

    (you can similarly do for the controller if it never reaches the action or other cases e.g. ControllerBuilder.Current.SetControllerFactory(new RedirectControllerFactory()); where factory derives from DefaultControllerFactory similar to below example)

    …then in the code somewhere you define the binder like this, simplified…

    public class OAuthProviderClassBinder : DefaultModelBinder
    {
        //public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        //{
        //}
        protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
        {
            var model = (OAuthProvider)base.CreateModel(controllerContext, bindingContext, modelType);
    
            // ...you change, inspect set etc.
    
            return model;
        }
    }
    

    …this is the way to custom bind, adjust your ‘passing’ values – also check if problems with them etc.
    And you might be better off overriding the other methods, e.g. BindModel

    Here are a link fast…
    Creating a custom model binder
    http://msdn.microsoft.com/en-us/library/system.web.mvc.defaultmodelbinder.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following domain model: public class Name { private readonly string fullName;
I have the following Model: public class Person { public string Name {get;set;} public
I have the following model: public class Person { public string Name { get;
I have the following model: public class Contact { public Contact() { Name =
I have the following Model: public class DeliveryTracking { public string TrackingRef { get;
So I have the following model: public class Person { public String FirstName {
I have following model: public class FormularModel { [Required] public string Position { get;
I have the following model public class UserViewModel { public String CVR_Nummer { get;
I have the following model in MVC: public class ParentModel { public string Property1
I have the following model: [DataContract] public class MessageHeader { private Guid? messageId; public

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.