Note that there are some explanatory texts on larger screens.

plurals
  1. PODropdownlist SelectedItemChanged Event in MVC4 Razor?
    primarykey
    data
    text
    <p>Is there any event available for Dropdownlist like onChange, etc. in MVC4? Do we have to use Javascript/jQuery in order to make some manipulations like DropwowlistSelectedItemChanged, etc? Or there is a way only using the Razor or MVC4 features?</p> <p>On the other hand, could you please give me some examples how can I retrieve data and change a label's text with this data according to a Dropdownlist Selected Value? For example when selecting a City from Dropdownlist, I want to get an address data from database by using the selected city id and then show retrieved address on a label. I would be appreciated if you clarify me about the issue above and give me an example to achieve this.</p> <p><strong>Controller:</strong></p> <pre><code>private void PopulateMeetingsDropDownList(object selectedMeetings = null) { var meetingsQuery = repository.Meetings .Join(repository.Cities, m =&gt; m.MeetingCityId, c =&gt; c.CityID, (m, c) =&gt; new { CityID = c.CityID, CityName = c.CityName, MeetingDate = m.MeetingStartDate } ) .OrderBy(x =&gt; x.CityID) .AsEnumerable() .Select( i =&gt; new { CityID = i.CityID, DisplayValue = string.Format( "{0} ({1:dd MMMM yyyy})", i.CityName, i.MeetingDate) } ).ToList(); ViewData["MeetingId"] = new SelectList(meetingsQuery, "CityID", "DisplayValue", selectedMeetings); } </code></pre> <p><strong>View:</strong></p> <pre><code>&lt;label&gt;Meeting&lt;/label&gt; @Html.DropDownListFor(m =&gt; m.MeetingId, ViewData["MeetingId"] as SelectList,"---- Select ----", new { name = "meetingId", id = "meetingId"}) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload