Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas 66 posts 88 karma points
    Dec 13, 2011 @ 15:32
    Thomas
    0

    new Member () doesn't accept variable

    Hi I keep getting this error message when inserting a variable instead of a harcoded number in new Member()

    My code looks like this and actually returns two errors

      var profileID = HttpContext.Current.Request.QueryString["profileID"];
      if (profileID != null) {
        var member = new Member(profileID);
      } else {
        var member = new Member(currentMember);
      }

    First of all the if sentence doesn't work - none of the conditions are run (tested with hardcoding the member numbers). 

    New Member (1200); works fine, but inserting profileID instead of a hardcoded number returns this error message:

    The best overloaded method match for 'umbraco.cms.businesslogic.member.Member.Member(int)' has some invalid arguments

    I guess there is something wrong with the profileID variable. What am I missing?

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 13, 2011 @ 15:33
    Sebastiaan Janssen
    0

    You probably need to do int.Parse(profileID) as Request.QueryString returns a string.

  • Thomas 66 posts 88 karma points
    Dec 13, 2011 @ 16:14
    Thomas
    0

    Yes, converting profileID to an integer solved one of the issues. I used AsInt() instead, but you are right.

    It didn't solve the problem with my if sentence. It seems like it isn't decalring the member variable in any case.

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 13, 2011 @ 16:29
    Sebastiaan Janssen
    0

    Ah, well you're declaring the new member inside the if/else. It's only usable in that scope. You probably want it to be more like this (untested):

     Member member;
     
    var profileID = HttpContext.Current.Request.QueryString["profileID"];
      if (profileID != null) {
        member = new Member(profileID);
      } else {
        member = new Member(currentMember);
      }

     <span>Member ID is: @member.Id</span>
  • Thomas 66 posts 88 karma points
    Dec 13, 2011 @ 16:39
    Thomas
    1

    You're brilliant - thanks that did it :o)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies