0

I tried everything I know to refresh the page. this is my code:

 @Html.DropDownList("Languages", "Select Language")

I tried:

 @Html.DropDownList("Languages", "Select Language", new { @onchange = "this.form.submit();" })

and without the @onchange (onchange), I tried to make javascript but it just wont add another parameter after my "select language" it always says "invalid arguments" so yeah, what else can i do to Select Item and then refresh the page?

EDIT

So to clarify, I have this dropdownlist

List<SelectListItem> Languages = new List<SelectListItem>();
Languages.Add(new SelectListItem { Text = "Hungarian", Value = "hu" });
Languages.Add(new SelectListItem { Text = "Hrvatski", Value = "hr" });
Languages.Add(new SelectListItem { Text = "Slovak", Value = "sk" });
Languages.Add(new SelectListItem { Text = "Bosanski", Value = "hr" });
Languages.Add(new SelectListItem { Text = "English", Value = "en" });       
Languages.Add(new SelectListItem { Text = "Srpski", Value = "sr" });

in my controller, now when I click on <button type="submit">next</button> it changes the language of the page by the value I selected

13
  • what exactly you need to do ? Commented Feb 23, 2015 at 14:03
  • after selecting item, to change the language of the page, that means a a postback, i have a Submit button, witch works perfectly. I select language in Dropdown box and press button = language changed. How to do that without the button. Commented Feb 23, 2015 at 14:05
  • button code <button type="submit">next</button> Commented Feb 23, 2015 at 14:05
  • what the button do in your page ? Commented Feb 23, 2015 at 14:10
  • "submit" just that, and the page changes language. Commented Feb 23, 2015 at 14:11

2 Answers 2

3

There is no AutoPostBack in MVC you can achieve this by JQuery like this:

$("#Languages").change(function () {
    // You can refresh your page by code
    //  location.reload();
});

Or bind change to your DropDown like:

$("#Languages").bind("change",function(){
    // You can refresh your page by code
    //  location.reload();
});
Sign up to request clarification or add additional context in comments.

Comments

2

So what i did was @Html.DropDownList("Languages", null, new { @onchange = @"form.submit();"})

and it worked.. so yeah thanks guys!

Comments

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.