This is a migrated thread and some comments may be shown as answers.

[Solved] How Do I Get the Value From My DropDownList?

4 Answers 154 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jerry
Top achievements
Rank 1
Jerry asked on 04 Sep 2011, 01:32 PM
I know this must be a newbie question and there's no lack of DDL examples about, but I can't make this work:

Simple view with a DropDownList and an Upload control:
@model UploadStatementViewModel
                  
@{ Layout = "~/Views/Shared/_LayoutTwoColumns.cshtml"; }
 
<div class="paneheader">Upload Statements</div>
 
@using (Html.BeginForm())
{
    <div>Select the appropriate statement parser:</div>
 
    <p>
    @(Html.Telerik().DropDownList()
        .Name("selectedParser")
        .HtmlAttributes(new { style = "width: 300px;" })
        .BindTo(PicklistHelper.ParserPicklist())
        )
    </p>
 
    <p>
    @(Html.Telerik().Upload()
        .Name("file")
        .Multiple(false)
        .Async(async => async
            .Save("Save", "Statement")
            .AutoUpload(true))
        )
    </p>
}

View Model:
public class UploadStatementViewModel
{
    public HttpPostedFileBase file { get; set; }
    public string selectedParser { get; set; }
}

My Save actiion is getting triggered without a problem, but only the file property is populated.  I expected the value from the drop down list to be in selectedParser, but it's always null.

What do I need to do to get that value to flow back to the controller?

Thanks.
J





4 Answers, 1 is accepted

Sort by
0
Sébastien
Top achievements
Rank 1
answered on 07 Sep 2011, 12:30 AM
I have the same issue using the following code

@using (Html.BeginForm("MyAction", "AController", FormMethod.Post))
{
    <div>
        <div style="float:left;line-height:22px;margin-right:5px;margin-bottom:10px">Selected Log File : </div>
        @Html.Telerik().DropDownList().Name("S").BindTo(Model.Files).HtmlAttributes(new { style = "float:left;line-height:17px;margin-right:5px"})
        <button class="t-button t-state-default" type="submit" style="float:left;line-height:16px">Load</button>
        <div style="clear:both"></div>
    </div>
}

I didn't get the selected value and my Model back.
Version used : 2011.2.715
0
Georgi Krustev
Telerik team
answered on 07 Sep 2011, 08:35 AM
Hello Sébastien,

 
This is not a known issue. Could you reproduce the depicted issue using this online demo? In order to proceed with the investigation I will ask you to send us a simple test project which replicates the problem. Thus I will be able to review it locally and advice you further.

Kind regards,
Georgi Krustev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Jerry
Top achievements
Rank 1
answered on 07 Sep 2011, 01:17 PM
To be clear...  I have no problem with the drop down list, in general.  But when I add the File Upload control in AutoUpload mode, that's when I stop receiving the DDL value.  It has something to do with the way the Upload control is posting back, I'm guessing...

Does that make a difference?

Thanks.

J
0
Georgi Krustev
Telerik team
answered on 08 Sep 2011, 09:24 AM
Hello Jerry,

 
If you need to send the value of the DropDownList to the Save Action method when upload the file, then you will need to use onUpload event of the Upload UI component. In the event handler you will need to extend the e.data with the data which you need to send:

[View]:

function onUpload(e) {
   var dropDownListValue = "1";
 
   e.data = { ddlValue: dropDownListValue };
}

[Controller]:
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments, string ddlValue) {
 
....
 
}

Check this help topic for more information.
Regards,
Georgi Krustev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
ComboBox
Asked by
Jerry
Top achievements
Rank 1
Answers by
Sébastien
Top achievements
Rank 1
Georgi Krustev
Telerik team
Jerry
Top achievements
Rank 1
Share this question
or