How to get selected value in the dropdownlist in Asp.Net MVC

0

How to get the selected value in dropdownlist ? I need to get the selected value and pass this value to a session . I did with textbox that way and it worked, but with dropdownlist does not take the value. I've done the following:

View

  @Html.DisplayNameFor(model => model.IRPJ) : 
                    @Html.DropDownListFor(model => model.IRPJ, new SelectList(new List<Object> 
               {
                   new { value = 0, text = "1,5"},
                   new { value = 1, text = "4,8"}
               }, "value", "text", 0))

Controller

 [HttpPost]
        public ActionResult Detalhes(FormCollection frm)
        {
             object irpj = frm[1].ToString().Replace(".",",");
             Session["IRPJ"] = irpj;

            return RedirectToAction("ImprimirBoleto", new
            {
                irpj = Session["IRPJ"].ToString(),
            });
    
asked by anonymous 27.08.2015 / 22:01

1 answer

2

You do not need the FormCollection parameter in this case.

[HttpPost]
    public ActionResult Detalhes(string IRPJ)
    {

         Session["IRPJ"] = IRPJ.Replace(".",",");

        return RedirectToAction("ImprimirBoleto", new
        {
            irpj = Session["IRPJ"].ToString(),
        });
    
27.08.2015 / 22:10