dimanche 5 février 2017

My dropdown selected value is not being posted to the controller in C# mvc

I am new to C# mvc. I have a simple form containing a dropdown list whose values are being populated from a ViewBag

@using (Html.BeginForm("GetSliderValues", "Slider",FormMethod.Post))
    {
   @Html.DropDownList("dvalue",(IEnumerable<SelectListItem>)ViewBag.names)

        <input type="submit" name="submit" value="Submit" />
    }

After submitting the form I am trying to get the selected value in the Controller as

[HttpPost]
    public ActionResult GetSliderValues()
    {
        ProviderName p = new ProviderName();
        p.Name = Request.Form["dvalue"];
        return View(p);

    }

But I am not receiving any value. p.Name is always being set to null.

Aucun commentaire:

Enregistrer un commentaire