QiFeng.ZWY.Utility/MvcHelper/RadioBoxListHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;
namespace QiFeng.LMSD.Utility.MvcHelper
{
public static class RadioBoxListHelper
{
public static MvcHtmlString RadioBoxList(this HtmlHelper helper, string name)
{
return RadioBoxList(helper, name, helper.ViewData[name] as IEnumerable<SelectListItem>, new { });
}
public static MvcHtmlString RadioBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> selectList)
{
return RadioBoxList(helper, name, selectList, new { });
}
public static MvcHtmlString RadioBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> selectList, object htmlAttributes)
{
IDictionary<string, object> HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
HtmlAttributes.Add("type", "radio");
HtmlAttributes.Add("name", name);
StringBuilder stringBuilder = new StringBuilder();
int i = 0;
int j = 0;
foreach (SelectListItem selectItem in selectList)
{
string id = string.Format("{0}{1}", name, j++);
IDictionary<string, object> newHtmlAttributes = HtmlAttributes.DeepCopy();
newHtmlAttributes.Add("value", selectItem.Value);
newHtmlAttributes.Add("id", id);
var selectedValue = (selectList as SelectList).SelectedValue;
if (selectedValue == null)
{
if (i++ == 0)
newHtmlAttributes.Add("checked", null);
}
else if (selectItem.Value == selectedValue.ToString())
{
newHtmlAttributes.Add("checked", null);
}
TagBuilder tagBuilder = new TagBuilder("input");
tagBuilder.MergeAttributes<string, object>(newHtmlAttributes);
string inputAllHtml = tagBuilder.ToString(TagRenderMode.SelfClosing);
stringBuilder.AppendFormat(@" {0} <label for='{2}'>{1}</label>",
inputAllHtml, selectItem.Text, id);
}
return MvcHtmlString.Create(stringBuilder.ToString());
}
private static IDictionary<string, object> DeepCopy(this IDictionary<string, object> ht)
{
Dictionary<string, object> _ht = new Dictionary<string, object>();
foreach (var p in ht)
后面还有 7 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。