Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jun 21, 2013 @ 10:11
    Ismail Mayat
    0

    Custom field type in razor

    Guys,

    I have created a custom field type country picker using http://our.umbraco.org/forum/umbraco-pro/contour/27135-country-picker-in-Contour?p=0 I am using contour razor macro. I need to render out the country list as a drop down list but not sure how todo this. Any ideas?

    Looking at the code for dropdown list  in FieldType.DropDownList.cshtml we have

    @model Umbraco.Forms.Mvc.Models.FieldViewModel

    <select name="@Model.Name" id="@Model.Id"

    @if (Model.Mandatory){<text> data-val="true" data-val-required="@Model.RequiredErrorMessage"</text>}

    >

        <option value=""></option>

        @foreach (var pv in Model.PreValues)

        {

            <option value="@pv.Value" 

            @if (Model.ContainsValue(pv.Value))

            {<text>selected="selected"</text>}

            >@pv.Value</option>

        }

    </select>

    However this does not render anything am i missing something? Also in the backend the llist should be populated as well? Currently its not ?

    Regards

     

    Ismail

  • Comment author was deleted

    Jun 21, 2013 @ 10:36

    Hey Ismail,

    If you take a look at the code you are using from that post it uses the publicoverrideSystem.Web.UI.WebControls.WebControlEditor and that is only used with the usercontrol macro, the razor one doesn't use that webcontrol

    What you can do is just write the loop in your razor view so replace

    @foreach (var pv in Model.PreValues)

    with a loop of countries CultureInfo.GetCultures(CultureTypes.SpecificCultures);

  • Comment author was deleted

    Jun 21, 2013 @ 10:37

    Or you could also use this prevalue source instead bonus is that that one is multilingual :) http://www.nibble.be/?p=217

  • Comment author was deleted

    Jun 21, 2013 @ 10:45
Please Sign in or register to post replies

Write your reply to:

Draft