Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
public ActionResult bindddl()
       {
           List<CRBT_SongMaster> titlelist = new List<CRBT_SongMaster>();
           var TitleLST = new List<string>();
           var GenreQuery = from z in dbcontext.CRBT_SongMaster orderby z.SongId select z.TitleAlbum;
               TitleLST.AddRange(GenreQuery.Distinct());
               ViewBag.TitleList = new SelectList(TitleLST);
              return View("bindddl", titlelist);
       }



This is my action method above.

below is my view page....

Album List


@Html.DropDownList("TitleList", "----Select Album Title----")

please help me how will I get value from this dropdownlist ?
Posted

try with this in post action.

C#
Album .title = Convert.ToInt32(Request["TitleList"]);
 
Share this answer
 
@Html.DropDownListFor(Model=>Model.AlbumTitle, new List<selectlistitem>
{
new SelectListItem{ Text="Equities", Value = "5" },
new SelectListItem{ Text="Bonds", Value = "1" },
new SelectListItem{ Text="CDS", Value = "2" },
new SelectListItem{ Text="ADS", Value = "3" },
new SelectListItem{ Text="EDC", Value = "4" }
}, "--Select Album--",new { style = "width: 153px;" })




[HttpPost]
public ActionResult bindddl( Model objModel)
{
//Here Get Dropdown list value
string str=objModel.AlbumTitle;

}
 
Share this answer
 
SQL
In Controller
ViewBag.StateList = (from s in _db.StateMasters
                                select s).ToList();

In View
 <div class="control-group">
                        <div class="controls">
                            <div class="form-label ">
                                State "star">*</div>
                            @Html.DropDownListFor(model => model.State,
                                      new SelectList(ViewBag.StateList, "StateName", "StateName"), "-- Select --", new { @class = "span12 cusmo-input" })
                            @Html.ValidationMessage("State", new { @style = "color:red" })
                        </div>
      
              </div>

In controller

 objCust.State = model.State == null ? string.Empty : model.State;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900