Im trying to create a from using asp.net mvc3.
I have a dropdownlist with some options. What i want is different partial views to be injected into the page, depending on the selection in the dropdown list.
But. i dont want this to rely on a submit action. It should function so that, the partial view is loaded as soon as you select from the select list.
I have this code:
@using (Ajax.BeginForm("Create_AddEntity", new AjaxOptions {
UpdateTargetId = "entity_attributes",
InsertionMode = InsertionMode.Replace
}
))
{
<div class="editor-label">
@Html.Label("Type")
</div>
<div class="editor-field">
@Html.DropDownList("EntityTypeList", (SelectList)ViewData["Types"])
</div>
<div id="entity_attributes"></div>
<p>
<input type="submit" value="Create" />
</p>
}
But I can't figure out how to trigger this partial view load when the dropdown list selection changes.
This point is that the form is different for the different "entity types". so there will be loaded a different partial view, depending on the dropdown selection.
Anyone got any pointers?
add the following code to the header of the project (layout). Add "combobox" to any combo box (select box) which you want to trigger the form that is surrounding it.
Let's say following is your view that you want to insert your partial.
On the change event of your dropdownlist, get partial via jquery ajax call and load it to place holder.
And in your controller action which is /Controller/MyActionin above jquery, return your partial view.