Click here to Skip to main content
16,007,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to get the value of ViewData on view when DropDownListFor selection is changed.

Scenario:
I have created a view with a dropdown, and a label.
HTML
<div class="FQA">Quote:</div> <div>
            <%:Html.DropDownListFor(x=>x.Person.Days, new SelectList(Model.Person.Days), new {onChange = "this.form.action='Home/SelectedIndexChanged';this.form.submit();" } )%>
        </div>
<%:ViewData["ddlVal"].ToString() %>


Action
C#
public ActionResult SelectedIndexChanged() {
            ViewData["ddlVal"] = "Changed";
            }

Now i want to update the label with drop down selected item data when drop down selection is changed.
Posted
Updated 5-Dec-11 22:49pm
v2
Comments
[no name] 6-Dec-11 4:49am    
EDIT: added code block

1 solution

you can simply add a line in your code...

Quote:
public ActionResult SelectedIndexChanged() {
ViewData["ddlVal"] = "Changed";
}


add this :

C#
public ActionResult SelectedIndexChanged() {
            ViewData["ddlVal"] = "Changed";
            return View(YourViewName);
            }



This might work. Let me know if any issues...

-Sagar Solanki
 
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