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

Martijn picture Martijn · Apr 8, 2009 · Viewed 27.2k times · Source

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?

Answer

Christian C. Salvad&#243; picture Christian C. Salvadó · Apr 8, 2009

You can use the onchange client event:

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