gpt4 book ai didi

c# - 如何根据 ViewBag 中包含列表的元素显示文本框

转载 作者:行者123 更新时间:2023-12-03 12:34:35 27 4
gpt4 key购买 nike

这是我的 Controller 代码:

const string template = "clm_adj_process_cd ('@[CdCode]',varchar) ~f.src_dm_platform_cd ('@[EM]'==,varchar) ~paid_date_skey('@[22/09/12]',date)";

string[] arr = template.Split('~');
List<string> list = new List<string>();
List<string> list2 = new List<string>();

foreach (string a in arr)
{
string[] sub1 = a.Split('(');
list.Add(sub1[0]);
string[] sub2=sub1[1].Split(',');
string[] sub3 = sub2[1].Split(')');
list2.Add(sub3[0]);


}



ViewBag.Label = list;
ViewBag.DataType = list2;
return View();

这是我在 View 中的代码:

<div>
@foreach (var label in ViewBag.Label)
{
@label

<br /><br />
}

</div>

这正在显示第一个列表。

沿着第一个列表的每个元素,我需要放置一个文本框或日期选择器等取决于 list2 中的元素

最佳答案

您需要将其转换为 List<string>

  <div>
@foreach (var label in (List<string>)ViewBag.Label)
{
@label

<br /><br />
}

</div>

关于c# - 如何根据 ViewBag 中包含列表的元素显示文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23788050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com