开发者

Simple Asp.Net MVC2 Binding question: How to get an EditorFor to render a Radio Button Group?

开发者 https://www.devze.com 2022-12-20 04:38 出处:网络
Just thinking out loud about the s开发者_开发知识库ubject, If I have the following: <%= Html.EditorFor(m => m.Gender, \"Gender\")

Just thinking out loud about the s开发者_开发知识库ubject, If I have the following:

 <%= Html.EditorFor(m => m.Gender, "Gender")

And I want it to render two radio buttons:

 O Male  O Female

Assuming the class just has a string to hold the value, what would the Gender.ascx look like if we were to pass the Gender values using something like

 ViewData["Gender"] = new string[] {"Male", "Female"};


This is a Radio button example (Yes No):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.RadioButton("", "Yes") %> Yes
<%= Html.RadioButton("", "No") %> No

And another Radio Button set (Gender):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.RadioButton("", "Male") %> Male
<%= Html.RadioButton("", "Female") %> Female

And a Drop Down Menu (Marital Status):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.DropDownList("", new SelectList(new[] {"N/A",
    "Single", "Married", "Divorced", "Widowed" })) %>

Now I need to modify these to look for a matching ViewData[""] list of options or figure out how to pass a selection list to the partial UI Template.

0

精彩评论

暂无评论...
验证码 换一张
取 消