Razor 如何在MVC5中格式化动态控件
在我的MVC5视图中的以下代码中,我正在动态构建label和textbox控件,但我需要在表中对它们进行格式化,因此我不确定如何才能做到这一点Razor 如何在MVC5中格式化动态控件,razor,asp.net-mvc-5,Razor,Asp.net Mvc 5,在我的MVC5视图中的以下代码中,我正在动态构建label和textbox控件,但我需要在表中对它们进行格式化,因此我不确定如何才能做到这一点 @using InFlowConvertWeb.WebUI.Models @model InFlowConvertWeb.WebUI.Models.SearchControlListViewModel @{ ViewBag.Title = "List"; } @using (Html.BeginF
@using InFlowConvertWeb.WebUI.Models
@model InFlowConvertWeb.WebUI.Models.SearchControlListViewModel
@{
ViewBag.Title = "List";
}
@using (Html.BeginForm())
{
int searchControlIndex = 0;
foreach (SearchControl searchControl in Model.SearchControls)
{
switch (searchControl.ControlType)
{
case SearchControl.ControlTypes.TextBox:
{
<div class="form-group" style="margin-left: 15px">
@Html.Label(searchControl.FieldName,
new { @class = "col-md-12 control-label" })
@Html.TextBoxFor(
x => x.SearchControls[searchControlIndex].SearchValue)
@Html.HiddenFor(x => x.SearchControls[searchControlIndex].DataTable)
@Html.HiddenFor(x => x.SearchControls[searchControlIndex].FieldName)
</div>
break;
}
}
searchControlIndex += 1;
}
<div class="col-md-2">
<h2>
<input type="submit" value="Submit Selections" />
</h2>
</div>
@使用InFlowConvertWeb.WebUI.Models
@模型输入ConvertWeb.WebUI.Models.SearchControlListViewModel
@{
ViewBag.Title=“列表”;
}
@使用(Html.BeginForm())
{
int searchControlIndex=0;
foreach(模型中的SearchControl SearchControl.SearchControl)
{
开关(searchControl.ControlType)
{
case SearchControl.ControlTypes.TextBox:
{
@Html.Label(searchControl.FieldName,
新的{@class=“col-md-12控制标签”})
@Html.TextBoxFor(
x=>x.SearchControls[searchControlIndex].SearchValue)
@Html.HiddenFor(x=>x.SearchControls[searchControlIndex].DataTable)
@Html.HiddenFor(x=>x.SearchControls[searchControlIndex].FieldName)
打破
}
}
searchControlIndex+=1;
}
如有任何建议,将不胜感激
Bob试试这个例子:
@using InFlowConvertWeb.WebUI.Models
@model InFlowConvertWeb.WebUI.Models.SearchControlListViewModel
@{
ViewBag.Title = "List";
}
@using (Html.BeginForm())
{
<table id="dataTable" class="table table-bordered table-hover">
<tbody>
@{int searchControlIndex = 0;}
@foreach (SearchControl searchControl in Model.SearchControls)
{
switch (searchControl.ControlType)
{
case SearchControl.ControlTypes.TextBox:
{
<tr>
<td>
@Html.Label(searchControl.FieldName, new { @class = "col-md-12 control-label" })
</td>
<td>
@Html.TextBoxFor(x =>x.SearchControls[searchControlIndex].SearchValue)
@Html.HiddenFor(x =>x.SearchControls[searchControlIndex].DataTable)
@Html.HiddenFor(x =>x.SearchControls[searchControlIndex].FieldName)
</td>
</tr>
break;
}
}
searchControlIndex += 1;
}
</tbody>
</table>
<div class="col-md-2">
<h2> <input type="submit" value="Submit Selections" /> </h2>
</div>
}
@使用InFlowConvertWeb.WebUI.Models
@模型输入ConvertWeb.WebUI.Models.SearchControlListViewModel
@{
ViewBag.Title=“列表”;
}
@使用(Html.BeginForm())
{
@{int searchControlIndex=0;}
@foreach(模型中的SearchControl SearchControl.SearchControl)
{
开关(searchControl.ControlType)
{
case SearchControl.ControlTypes.TextBox:
{
@Label(searchControl.FieldName,新的{@class=“col-md-12控制标签”})
@Html.TextBoxFor(x=>x.SearchControls[searchControlIndex].SearchValue)
@Html.HiddenFor(x=>x.SearchControls[searchControlIndex].DataTable)
@Html.HiddenFor(x=>x.SearchControls[searchControlIndex].FieldName)
打破
}
}
searchControlIndex+=1;
}
}
试试这个例子:
@using InFlowConvertWeb.WebUI.Models
@model InFlowConvertWeb.WebUI.Models.SearchControlListViewModel
@{
ViewBag.Title = "List";
}
@using (Html.BeginForm())
{
<table id="dataTable" class="table table-bordered table-hover">
<tbody>
@{int searchControlIndex = 0;}
@foreach (SearchControl searchControl in Model.SearchControls)
{
switch (searchControl.ControlType)
{
case SearchControl.ControlTypes.TextBox:
{
<tr>
<td>
@Html.Label(searchControl.FieldName, new { @class = "col-md-12 control-label" })
</td>
<td>
@Html.TextBoxFor(x =>x.SearchControls[searchControlIndex].SearchValue)
@Html.HiddenFor(x =>x.SearchControls[searchControlIndex].DataTable)
@Html.HiddenFor(x =>x.SearchControls[searchControlIndex].FieldName)
</td>
</tr>
break;
}
}
searchControlIndex += 1;
}
</tbody>
</table>
<div class="col-md-2">
<h2> <input type="submit" value="Submit Selections" /> </h2>
</div>
}
@使用InFlowConvertWeb.WebUI.Models
@模型输入ConvertWeb.WebUI.Models.SearchControlListViewModel
@{
ViewBag.Title=“列表”;
}
@使用(Html.BeginForm())
{
@{int searchControlIndex=0;}
@foreach(模型中的SearchControl SearchControl.SearchControl)
{
开关(searchControl.ControlType)
{
case SearchControl.ControlTypes.TextBox:
{
@Label(searchControl.FieldName,新的{@class=“col-md-12控制标签”})
@Html.TextBoxFor(x=>x.SearchControls[searchControlIndex].SearchValue)
@Html.HiddenFor(x=>x.SearchControls[searchControlIndex].DataTable)
@Html.HiddenFor(x=>x.SearchControls[searchControlIndex].FieldName)
打破
}
}
searchControlIndex+=1;
}
}
你是在问如何用HTML制作
吗?你是在问如何用HTML制作
?