How to keep option after refresh - Asp.net

Asked

Viewed 171 times

1

I have a select, some options and a jquery code that in select change, updates the screen with the data of the chosen option. The question is, how do I maintain the option after window.Location? Obs: am using Asp.Net

Code I have:
View:

<select id="servicos">
    @foreach (var i in servicos)
    {
        <option value="@Url.Content("~/servico/"+i.SiteInfoID+"/"+i.Titulo.html)">
            @i.Titulo
        </option>
    }
</select>

Js:

function ComboServicos() {
    $('#servicos').on('change', function () {
        var url = $(this).val();
        if (url) {            
            window.location = url;
        }
        return false;
    });
}
  • You can go through querystring or save to the server, and then take this value and leave as selected with JS

1 answer

0

By having the parameter sent put it in a Viewbag for example and recover in the View so that you can filter by doing an if to put the "Selected" option

Browser other questions tagged

You are not signed in. Login or sign up in order to post.