Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to get selected item text in razor dropdownlist.

how to get selected item text in razor dropdownlist.

Scheduled Pinned Locked Moved ASP.NET
htmlasp-nettutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GuhananthS
    wrote on last edited by
    #1

    <form id="MonthlyAward" action="@Url.Action("SubmitAwards", "MonthlyAward")" method="post"> @Html.DropDownListFor(m => m.ddlProjectsID, Model.ProjectNames, "--Select--", new { id = "ddlProjects",name="ddl_ProjectnameText", onchange = "document.getElementById('TheForm').submit();" }) how to get selected item text in form collection

    [HttpPost]
    public ActionResult SubmitAwards(FormCollection collection, MonthlyAwardModel award)
    {
    string strProjectId = collection["ddlProjectsID"].ToString().Trim();
    return View();

    M 1 Reply Last reply
    0
    • G GuhananthS

      <form id="MonthlyAward" action="@Url.Action("SubmitAwards", "MonthlyAward")" method="post"> @Html.DropDownListFor(m => m.ddlProjectsID, Model.ProjectNames, "--Select--", new { id = "ddlProjects",name="ddl_ProjectnameText", onchange = "document.getElementById('TheForm').submit();" }) how to get selected item text in form collection

      [HttpPost]
      public ActionResult SubmitAwards(FormCollection collection, MonthlyAwardModel award)
      {
      string strProjectId = collection["ddlProjectsID"].ToString().Trim();
      return View();

      M Offline
      M Offline
      mr priyank
      wrote on last edited by
      #2

      There are two ways. 1. Have a hidden field in the page and set the value of that field as $("#hiddendfield").val($("#ddlProjectsID option:selected").text()); You need to this on OnChange event of the dropdown. after that call the form submit method. it will be better if you use $.ajax of the jquery for submission. Then in by using formcollection you can get the value of that hidden field in the controller. 2. have the list again in the controller and fire a query in that list against the id selected. now you have the selected item and you can get the display text

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups