I'm trying to figure out how to get a @Html.DropDownList to direct to another Action on the onChange() event of the select it creates, the action name being stored in the option values of the select list. The closet I've gotten so far is this:
View:
@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{
<h5>Select service to test:</h5>
@Html.DropDownList("ddl", new SelectList(Model.Services, "MvcActionName", "ServiceName"),
new {
onchange = @"
var form = document.forms[0];
var action = $('#ddl').val();
form.action=action;
form.submit();"
})
}
And what it emits is this:
<form action="/" method="get"> <h5>Select service to test:</h5>
<select id="ddl" name="ddl" onchange="
var form = document.forms[0];
var action = $("#ddl").val();
form.action=action;
form.submit();"><option value="">Ping Service</option>
<option value="Data">Data Service</option>
</select>
</form>
But all this does is try to call "localhost/Data" and fail because it should be calling "localhost/Home/Data". I'm using the standard MVC3 routing setup, but so far I haven't been able to make a change there that causes the BeginForm helper to emit a better form block either.
Then again, I'm not sure routing is even the issue or if I'm taking a poor path to get to where I want to be going. Any help or guidance would be greatly appreciated.