Postback on RadioButtonFor in MVC

Null Pointer picture Null Pointer · Feb 12, 2011 · Viewed 11k times · Source

I have 2 radio buttons in my mvc webpage.

 <% using (Html.BeginForm("Search", "Search"))
   { %>
  // some html codes
     <%= Html.RadioButtonFor(m => m.Agents, "A", new { Checked = "checked" })%> //radio button 1                     
      <%= Html.RadioButtonFor(m=> m.Agents,"AG") %>  //radio button 2                      
  // some html codes
   <% } %>

the aspx page is shown below.

I also have button in my page.and if i clicked on that button,then there is a postback occures.

I need another postback if i changed radiobutton selection. How can i make postback on that event.But there is no postback if i changed the selection of radio buttons. How can i achieve this?

Answer

Murtaza H picture Murtaza H · Dec 7, 2012

this is one way of doing post back with radio button:

<label>@Html.RadioButton("Buyer", "Buyer", new { onchange = "this.form.submit();" })Buyer</label>