Get DropDownList Selected Text when not using Model in ASP.Net MVC

Last Reply 8 days ago By dharmendr

Posted 9 days ago

How to Get Dropdownlist value in mvc

   <div class="form-group">
        @Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
        @{
        List<SelectListItem> listItems = new List<SelectListItem>();
        listItems.Add(new SelectListItem
        {
            Text = "Active",
            Value = "1"
        });
        listItems.Add(new SelectListItem
        {
            Text = "No-Active",
            Value = "2"
        });
                    }
                    @Html.DropDownList("ddlstatus", new SelectList(listItems, "Value", "Text"))
                   
                    @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
                </div>
            </div>

Controller code--

public ActionResult Category(tbl_Category category,  int ddlstatus) {

 tbl_Category categry = new tbl_Category();

 categry.Status = ddlstatus;

DB.tbl_Category.Add(categry); DB.SaveChanges();

}

 i am not able to get text of selected dropdown item

Posted 9 days ago

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html