views:

319

answers:

2

Hi, I'm trying to add a couple of radiobuttons at the top of a View (using ASP.NET MVC).

I want the two radiobuttons (option 1 and option 2) to cause the page to be refreshed/autoposted when changed.

The two radiobuttons live inside a separate .asxc (Menu.ascx), and added with Html.RenderPartial in a List.aspx page. The two options in turn determine if Html.RenderPartial("ListOption1Elements") or Html.RenderPartial("ListOption2Elements") is added to the page.

I've tried adding both Html.RadioButton and using <asp:RadioButtonList>, but haven't got it working properly. Only the last one of those has the AutoPostBack property I need, but it complains about not being inside a tag.

So, to sum up - how can I add two hardcoded radiobuttons that will cause a postback so that I in my Controller can determine which partial view to render?

+3  A: 

Postback concept is not supported in ASP.NET MVC as well as server controls in general.

You need to do it manually with JavaScript. Attach a function to the "onclick" event of a radiobutton and make an asynchronous call to a controller action that will simply issue a server side redirect to the same action that generated the view in question.

Developer Art
Could you give me an example of how to "make an asynchronous call to a controller" in JavaScript?
Frode Lillerud
A: 

EIDT -Ignore me, just noticed you're using MVC

new in town has the answer

wefwfwefwe