1
@Html.ActionLink("mor info","CityInfo",new{cityid = --getvalue()--},new {@class = "mbtn" })

I want to get Value Selected In Dropdownlist CityId With Jquery But I Can't Use JQuery Function in RouteValue

How to use JQuery Function in Routevalue? or How to Get selected CityId and Send To Action in Controller?

5
  • I think you didn't try to search out to achieve this. There are many possible methods to do this. Commented Dec 11, 2016 at 9:41
  • I Cant use Its solutions. can you help me? Thank you Commented Dec 11, 2016 at 9:47
  • I can Get CityId But I Cant Send to Controller. I need Sent Multiple Parameters. CityId One of several parameters Commented Dec 11, 2016 at 9:51
  • A piece of code makes a very bad title. Try describing your problem in that box. Commented Dec 11, 2016 at 12:45
  • thanks Henk Holterman Commented Dec 11, 2016 at 13:04

1 Answer 1

1

For example You can achieve this with jQuery function on dropdown value change event and setting element href attribute.

If You want, change <select /> to @Html.DropDownListFor() or @Html.DropDownList()

<script type="text/javascript">
    $(document).ready(function () {
        $('.myClass').change(function () {
            $('.mbtn').attr('href', '/MyController/CityInfo?cityid=' + $(this).val());
        });
    })
</script>

<select class="myClass">
    <option value="1">Texas</option>
    <option value="2">Sao Paulo</option>
    <option value="3">Mexico</option>
</select>

@Html.ActionLink("More Info", "CityInfo", null, new { @class = "mbtn" })

For more parameters You can for every dropdown set class='myClass' and different id. With it You should be able to use it as:

<script type="text/javascript">
    $(document).ready(function () {
        $('.myClass').change(function() {
            $('.mbtn').attr('href', '/MyController/CityInfo?cityid=' + $('#cityId').val() + '&userId=' + $('#userId').val());
        });
    })
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

really grateful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.