Keresés

Új hozzászólás Aktív témák

  • trisztan94

    őstag

    válasz martonx #4462 üzenetére

    Sehogy, mert kiszedtem azt az egész részt a kódómból, mert ahogy láttam az csak a viewbag változót hozza létre, így csak a fent leírt enum maradt. De visszarakom a viewbag-os megoldást, meglesem úgy:

    Na, így néz most ki a controller, visszatéve a viewbag-et:

    public enum Sexes { Válassz_egyet, Férfi, Nő, Nem_szeretném_megmondani };

    private void SetViewBagSex (Sexes Sex)
    {
    IEnumerable<Sexes> values =
    Enum.GetValues(typeof(Sexes))
    .Cast<Sexes>();

    IEnumerable<SelectListItem> items =
    from value in values
    select new SelectListItem
    {
    Text = value.ToString(),
    Value = value.ToString(),
    Selected = value == Sex,
    };
    ViewBag.Sex = items;
    }

    //
    // GET: /Regisztracio/

    public ActionResult Regisztracio()
    {
    SetViewBagSex(Sexes.Férfi);
    return View();
    }

    és így a view-ban a DropDownList:

    @Html.DropDownListFor(m => m.Sex, ViewBag.Sex)

    Erre a dropdownlist-re ezt az errort dobja a visual studio:

    'System.Web.Mvc.HtmlHelper<project.Models.RegisterModel>' has no applicable method named 'DropDownListFor' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax. c:\Users\Trisztán\Documents\Visual Studio

Új hozzászólás Aktív témák

Hirdetés