-1

I have a View that works but I can not figure out how to get the selected value from the DropDownList:

@model IEnumerable<TRP_MVC_Prototype.Models.usp_TM_Select_ShortNameResult>
@using System.Web;
@using System.Web.WebPages;
@using System.Web.Mvc;  

@{
    ViewBag.Title = "Details";
}
@using (Html.BeginForm("Details", "ProgramSummary", FormMethod.Post, new { id = "Details" }))
{
<div id="main" style="background-color:White">
        <h1 style="background-color:transparent;color:Blue;">
        <a>You are logged on as: @ViewBag.Message </a>
        <span class="DrpDwnLst">DrpDwnLst</span>
        @Html.DropDownList("Short_Title", new SelectList(Model, "short_title", "short_title"), "--Select One--").
        @Html.ActionLink("Select","Details",new { Shrt_title = ""})
        <a style="color:Blue;position:absolute; right:500px"> @Html.ActionLink("Create Program Summary", "Index", "User_Guide") </a>
        <a style="color:Blue;position:absolute; right:250px"> @Html.ActionLink("Edit Program Summary", "Index", "User_Guide")</a>
        <a style="color:Blue;position:absolute; right:50px"> @Html.ActionLink("Delete TRP", "Index", "User_Guide")</a>
        </h1>
        <h1 style="background-color:transparent;color:Blue;">Select TRP to View</h1>
        <h1 style="color:Gray";>______________________________________________________________________________________________________________________________________________________________________________</h1>
}

The DropDownList displays correctly but I don't know how to return the Selected value in the ActionLink. In the action link the third parameter passes the value back to the controller it currently has "" but I would like to figure out how to reference the selected value instead.

tereško
  • 58,060
  • 25
  • 98
  • 150
user1011441
  • 161
  • 2
  • 14
  • I am not following you. In the beginning you state that you want to get the selected value from your DropDown, but in the end you talk about action link. – Paulo Abreu Oct 27 '11 at 20:46
  • I want to return the selected value in the third parameter of the actionlink that currently says "new { Shrt_title = ""}) " replacing "" with something like item.short_title – user1011441 Oct 27 '11 at 20:59
  • possible duplicate of [Assigning the Selected value from a DropDownList](http://stackoverflow.com/questions/7880094/assigning-the-selected-value-from-a-dropdownlist) – Darin Dimitrov Oct 27 '11 at 21:28
  • It is the same problem. If this isn't possible let me know. I thought I would reword the problem. @Darin Dimitrov – user1011441 Oct 27 '11 at 21:31
  • If you think I am stupid please just let me know. I am not offended I would like an answer. Thank you Bruce – user1011441 Oct 27 '11 at 21:47
  • See my DDL tutorials http://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with-aspnet-mvc and http://blogs.msdn.com/b/rickandy/archive/2012/01/09/cascasding-dropdownlist-in-asp-net-mvc.aspx – RickAndMSFT Feb 14 '12 at 19:49

2 Answers2

0

You can do it with jquery. For changing href from a element you may see this post.

You also need to handle change event for your drop down:

$('#short_title').change(function() 
{
   // do someting here
});
Community
  • 1
  • 1
Paulo Abreu
  • 1,716
  • 11
  • 16
0

This is my answer

    @Html.DropDownList("short_name", ViewBag.DetailsList as SelectList, "--Select One--", new { onchange = "dofunction(this.form.short_name);" });
    function dofunction(dropdown) {
        debugger;
        for (i = 0; i < 194; i++) {
            if (dropdown[i].selected == true) {
                var Shrt_ttls = dropdown[i].value.toString()
                //document.getElementById("shrtLst").value = Shrt_ttls;

                $.ajax({
                    url: "/ProgramSummary/Details?Shrt_titles=" + Shrt_ttls,                 
                    type: 'Post',                 
                    data: Shrt_ttls,                 
                    success: function(result) { 
                        alert( "Short Name is: " + Shrt_ttls); // process the results from the controller action                 
                    },             
                    error: function () {
                         alert ( "no deal");
                    }
                });  
            }
        }
        return true;
     }

This returns the value from the javascript function to the HTTPPost for Index. Thank you, Bruce

glosrob
  • 6,631
  • 4
  • 43
  • 73
user1011441
  • 161
  • 2
  • 14