-1

I wish to pass 'selectlang' parameter in javascript and redirect to the MVC controller but the var 'selectlang' have error and mention that it does not exist in current content? Please guide me thanks!

My javascript:

 $('.filterlang').on("click", function () {
            var selectlang = document.getElementById("Language").value;
            location.href = '@Url.Content("~/SURV_Main/SURV_Main_Details/?key=" + Model.Survey_Key +"&Language=" + selectlang)';

        });

filterlang is button class and "Language" is dropdownlist id.

Edward.K
  • 556
  • 3
  • 11
  • 33

1 Answers1

0

Have you tried this:

$(document).on(".filterLang", "click", function(){
   var selectedLang = $("#Language").val(); // if it is normal dropdown, this will work for both cases
   var selected2Lang = $("#Language").select2("val"); // if it is select2 dropdown
   window.location = '@Url.Content("~/SURV_Main/SURV_Main_Details/?key=" + Model.Survey_Key +"&Language=' + selectlang + '")';
});

Hope this helps.

Igor Ilic
  • 1,370
  • 1
  • 11
  • 21
  • i have no idea why the var + selectlang not recognize :( it say it does not exist in current content. – Edward.K Sep 21 '15 at 07:58
  • @Edward.K I have update the code, you see one of the problems was that you were trying to access the value of selectedLang from c# code and it gave you and error because the c# does not have that variable declared. – Igor Ilic Sep 21 '15 at 08:06