简单的 Asp.Net MVC2 绑定问题:如何获取 EditorFor 来渲染单选按钮组?

发布于 2024-08-22 08:37:27 字数 313 浏览 8 评论 0原文

只是大声思考这个主题,如果我有以下内容:

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

并且我希望它呈现两个单选按钮:

 O Male  O Female

假设该类只有一个字符串来保存值,如果我们要传递 Gender.ascx 会是什么样子性别价值观使用类似

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

Just thinking out loud about the subject, 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"};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人如初 2024-08-29 08:37:27

这是一个单选按钮示例(是否):

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

另一个单选按钮集(性别):

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

和一个下拉菜单(婚姻状况):

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

现在我需要修改这些以查找匹配的 ViewData[""] 选项列表或弄清楚如何将选择列表传递到部分 UI 模板。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文