alexanderar / Mvc.CascadeDropDown

MIT License
26 stars 12 forks source link

Implementing Create.cshtml in real world application #16

Closed BillieBishop closed 7 years ago

BillieBishop commented 7 years ago

I really try hard to implement your nuget helper. But my cascading DropDownListFor (the dependant one) does not show anything. I think it is because of my ActionResult. Would you be nice enough to help? p.s. I did read all your stuff from GitHub Mvc.CascadeDropDown, but cannot understand some. A tutorial for dummies would be great (I'm new to this stuff.)

So, this is my PlacesController.cs ActionResult: `public ActionResult GetRegionsByPaysId(int paysId) { var region = from r in db.Region where r.IdPays == paysId select r;

        return Json(new SelectList(region.ToArray(),
            "IdRegion", "NomRegion"), JsonRequestBehavior.AllowGet);
    }`

Now my Create.cshtml: @Html.CascadingDropDownListFor( expression: model => model.IdRegion, triggeredByProperty: model => model.IdPays, url: Url.Action("GetRegionsByPaysId", "Places"), ajaxActionParamName: "paysId", optionLabel: "", disabledWhenParrentNotSelected: true, htmlAttributes: new { @class = "form-control" })

Now my Models.cs (without the { get; set;} and yaketiyak) `public partial class Place { public int IdPlace public string NamePlace public int IdPays public int IdRegion

    public virtual Pays Pays
    public virtual Region Region
}

public partial class Pays {
public int IdPays public string CodePays public string NamePays

    public virtual ICollection<Place> Place 
    public virtual ICollection<Region> Region
}

public partial class Region { public int IdRegion public int IdPays public string NameRegion public string CodeRegion

    public virtual Pays Pays
    public virtual ICollection<Place> Place
}`

Thanks in advance, me. p.s. What is ajaxActionParamName?

BillieBishop commented 7 years ago

Forget about that. Following some weird law (don't know which one), I found my solution just after I asked it here. It's now 100% working. Thanks anyway.

p.s. How to erase my comment?