In my current view, there is a dropdown list that allows the user to select an option which will then redirect them to another page or controller. I am using JavaScript to retrieve the selected value from the dropdown list, but I am facing difficulties when trying to manipulate Html.BeginForm. The following snippet is part of my view:
@{ var newView=0;
var page = "";
var cont = "";
}
<script type="text/javascript" language="javascript">
function run() {
newView = document.getElementById('views').value;
}
function ButtonClicked() {
alert("View selected: " + newView );
// update variables page and cont here?
}
</script>
<select name="views" id="views" onchange="run()">
<option value="0"> </option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
@using (Html.BeginForm(page, cont, FormMethod.Post))
{
<button onclick="javascript:ButtonClicked()" type="submit" class="btn"> Go </button>
}
Is there a way for me to update the action of the submit button in a Razor view?
I have attempted to replace "Index" and "Home" with variables and update them within my functions, but it does not seem to be functioning as expected. Any suggestions on how to resolve this issue would be greatly appreciated.
-----Note: I revised my question to provide more clarity regarding the specific problem I am facing