Copied to clipboard

Flag this post as spam?

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


  • Kieron 152 posts 390 karma points
    Apr 11, 2018 @ 16:39
    Kieron
    0

    Membership Helper & nuPicker, cant get a ID

    Got the below code;

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @using System.Web.Mvc.Html
    @using ClientDependency.Core.Mvc
    @using Umbraco.Web
    @using Umbraco.Web.Models
    @using Umbraco.Web.Controllers
    
    @using umbraco.cms.businesslogic.member;
    @using Umbraco.Core;
    @using Umbraco.Core.Services;
    
    @{
        var loginModel = new LoginModel();
        var loginStatusModel = Members.GetCurrentLoginStatus();
        var logoutModel = new PostRedirectModel();
        var loginNodeID = 1961;
        var memberId = Members.GetCurrentMemberId();
        var member = ApplicationContext.Services.MemberService.GetById(memberId);
    
        @*loginModel.RedirectUrl = "/client-area";*@
    
        Html.EnableClientValidation();
        Html.EnableUnobtrusiveJavaScript();
        Html.RequiresJs("/umbraco_client/ui/jquery.js");
        Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
        Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
    }
    
    @* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@
    @Html.RenderJsHere()
    
        @if (loginStatusModel.IsLoggedIn)
        {
    
            @*var urlPoint = @member.project;
            HttpContext.Current.Response.Redirect(@urlPoint);*@
    
            var pickedProject = member.Properties["project"];
            @pickedProject.Value;
    
    
    
        }
            else {
    

    So currently this prints to the page as:

    [{"key":"1966","label":"The FA - Equality and Diversity"}]
    

    I need only the key here, any ideas guys

    thanks alot

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Apr 11, 2018 @ 19:53
    Hendy Racher
    1

    Hi Kieron,

    Does the following work ?

    @using System.Linq;
    
    @pickedProject.Value.PickedKeys.First()
    
  • Kieron 152 posts 390 karma points
    Apr 11, 2018 @ 20:35
    Kieron
    0

    Hey, with that, it comes back with:

    Compiler Error Message: CS1061: 'object' does not contain a definition for 'PickedKeys' and no extension method 'PickedKeys' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
    

    Thank you for helping!

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Apr 11, 2018 @ 20:41
    Hendy Racher
    0

    How about:

    @using System.Linq;
    @using nuPickers;
    
    @(((Picker)pickedProject.Value).PickedKeys.First())
    
  • Kieron 152 posts 390 karma points
    Apr 11, 2018 @ 20:52
    Kieron
    0
    Unable to cast object of type 'System.String' to type 'nuPickers.Picker'.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'nuPickers.Picker'.
    
    Source Error: 
    
    
    Line 45: 
    Line 46: 
    Line 47:         @(((Picker)pickedProject.Value).PickedKeys.First())
    

    I think we tried about 50 variations for this, but yours are new so that must be good, lol.

Please Sign in or register to post replies

Write your reply to:

Draft