I have a dropdown in my page. On selecting a value in dropdown I want the label text to be changed. Here is my code :
@model FND.Models.ViewLender
@{
ViewBag.Title = "Change Lender";
}
@using (Html.BeginForm())
{
@Html.Label("Change Lender : ")
@Html.DropDownList("Ddl_Lender", Model.ShowLenderTypes)
@Html.DisplayFor(model => model.Description)
}
On changing the value in dropdownlist I want the Description to change accordingly.
You could start by putting the description into a div and give your dropdown an unique id:
Now all that’s left is to subscribe to the
onchangejavascript event of this dropdown and update the corresponding description.For example if you are using jQuery that’s pretty trivial task:
This being said I probably misunderstood your question and this description must come from the server. In this case you could use AJAX to query a controller action that will return the corresponding description. All we need to do is provide the url to this action as an HTML5 data-* attribute to the dropdown to avoid hardcoding it in our javascript file:
and now in the
.changeevent we trigger the AJAX request:and the last step of course is to have this controller action that will fetch the corresponding description based on the selected value: