Copied to clipboard

Flag this post as spam?

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


  • Aaron 20 posts 180 karma points
    Aug 02, 2018 @ 16:07
    Aaron
    0

    Member Type Pre Values

    How can i pull down the pre values from the member type api to use on a registration form as a dropdown (select) box

    Thanks!

  • Aaron 20 posts 180 karma points
    Aug 03, 2018 @ 09:14
    Aaron
    101

    I have managed to solved this, a version of my code is below if others have this problem.

    On another note PreValues seem to have been removed from the Umbraco Wiki / Documentation

    Controller:

    [ChildActionOnly]
    [ActionName("NAME")]
    public ActionResult NAME()
    {
        return PartialView("~/Views/Partials/NAME.cshtml", new MODELNAME{NAME = GetSelectListForNAME()});
    }
    
            private SelectList GetSelectListForNAME()
            {
                var preValueDataType = Umbraco.DataTypeService.GetPreValuesCollectionByDataTypeId(1301); //Change Data Type ID
                var preValues = preValueDataType.PreValuesAsDictionary.Values.Where(pdv => pdv.Value != "0");
    
                var namesList = preValues.Select(preValue => new SelectListItem
                    {
                        Value = preValue.Id.ToString(),
                        Text = preValue.Value
                    })
                    .ToList();
                return new SelectList(namesList);
            }
    

    Model

    public SelectList NAMES { get; set; }
    
    public string NAME { get; set; }
    

    Razor View

    @Html.DropDownListFor(model => model.NAME, Model.NAMES.Items as List)
    
Please Sign in or register to post replies

Write your reply to:

Draft