如何在MVC 5中格式化动态控制



在以下代码中从我的MVC 5视图中,我动态构建标签和文本框控件,但我需要在表中格式化它们,以便我不确定如何做到这一点。<<<<<<<<<<<<<<<<

    @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>

任何建议都将不胜感激,

鲍勃

尝试此示例:

 @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>
}

最新更新