Search code examples
c#asp.net-mvccomboboxautopostback

C# How to set the autopostback property when using asp.net mvc?


I am using asp.net MVC framework. On my page i have a dropdwonbox and when an option is clicked i want to go to another page. But i can't find how/where to set the autopostback property to true. This is the code i'm using:

Aspx:

<%= Html.DropDownList("qchap", new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" )) %>

Controller:

public ActionResult Index(int id)
{
    Chapter c =  new Chapter();
    ViewData["qchap"] = c.GetAllChaptersByManual(id);

    return View();
}

What do i have to do to use the autopostback functionality?


Solution

  • You can use the onchange client event:

    <%= Html.DropDownList("qchap", 
           new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" ),
           new { onchange = "this.form.submit();" }) %>