I am quite new to this net mvc thing. to understand what I am trying to do I will put an example.
Example
I have a list of clients that contains data and in my view I used a <select>
with a foreach
that goes through all the clients to show the data. What I am trying to do is, when a user selects a client name he would be redirected to another page where that page would get the client name as a parameter & do stuff with that.
I tried this but I am stuck in a part
<select>
@foreach (var item in Model.clients)
{
<option>
@Html.Encode(item.name)
</option>
}
</select>
I know how to redirect from page A to page B like this RedirectToAction(...)
what I want to do is handle that select action to call the method in my controller & use that method to send a parameter to page B
UPDATE
<script type="text/javascript">
function Fct() {
var v = arguments[0]; //get The ID in the parameter
window.location.href = "@Url.Action("Index", "PageB")?client_id=" + v;
}
</script>
I tried both lists and the one proposed by @Shyui is easier but i wanted to try something with this one
<select id="clients_list" onchange="Fct(this.value)">
<option class="placeholder" selected disabled value="-1">Select Name</option> <!-- Can't be selected -->
@foreach (var item in Model.clients)
{
<option value="@item.ID">
@Html.Encode(item.name)
</option>
}
<option value="0">New Client</option>
</select>