how do radio buttons work with asp.net mvc binding -


I have a strongly typed object that represents all the text box properties of a form and when I post on the controller I am

Now I need to add a radio button to this form. How can I make that map firmly in typed objects?

If you use HtmlHelper.RadioButton, you will be fine unless your name is your property name Matches

Below is a snippet of code from one of my projects:

  & lt; Span & gt; & Lt;% = Html.RadioButton ("date", "MMMM / dd / yy", Model.DateFormat.Equals ("MMMM / dd / yy"), new dictionary & lt; string, object & gt; {{" Class "," normalwidth "}})%> & Lt; Label class = "displayinline" & gt; & Lt;% = DateTime.Now.ToString ("MMMM dd, yyyy")%> & Lt; / Label & gt; & Lt; / Span & gt; & Lt; Span & gt; & Lt;% = Html.RadioButton ("date format", "yay / mm / dd", model.dataformat.quals ("yyyy / mm / dd"), new dictionary & lt; string, object & gt; {{" Class "," normal width "}}}%>  

And the HTML presented here is to note that each input The same name, but different values. Only the selected button will be reverted back to the server.

  


Label & gt; date format & lt ; / Label & gt; & lt; span & gt; Input class = "normal width" id = "date format" name = "date format" type = "radio" value = "MMMM / dd / yy" Lt; label class = "displayinline"> October 18, 2009 gt; label class =" displayinline "> 2009/10/18 and lt; / label & gt; & lt; / span & gt; & lt; span & gt; input square =" normal width " Id = "date format" name = "date format" type = "radio" value = "dd / MM / yyyy" /> gt; label class = "displayline" & gt; 18 / 10/2009 and lt; / label & gt; & Lt; / Span & gt; & Lt; Span & gt; Input class = "normal" "id =" DateFormat "name =" DateFormat "type =" radio "value =" "/>

And in your class:

  public class posts {public string date format {get} set:}}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -