0
我想在剃刀視圖中的循環中使用下拉列表。下拉列表在初始頁面加載時正確顯示,但模型綁定在帖子上不起作用。在下拉列表中選擇的項目在帖子中不可用。 tableColumns屬性是空的。任何幫助將非常感激。從剃刀視圖中的循環中刪除列表
型號
public class DataMappingViewModel
{
public string TableName { get; set; }
public List<XmlElement> XmlElements { get; set; }
}
public class XmlElement
{
public string ElementName { get; set; }
public List<SP_GET_DBASE_COLUMNS_Result> tableColumns { get; set; }
}
public partial class SP_GET_DBASE_COLUMNS_Result
{
public string TABLE_CATALOG { get; set; }
public string TABLE_SCHEMA { get; set; }
public string TABLE_NAME { get; set; }
public string COLUMN_NAME { get; set; }
public Nullable<int> ORDINAL_POSITION { get; set; }
public string COLUMN_DEFAULT { get; set; }
public string IS_NULLABLE { get; set; }
public string DATA_TYPE { get; set; }
public Nullable<int> CHARACTER_MAXIMUM_LENGTH { get; set; }
public Nullable<int> CHARACTER_OCTET_LENGTH { get; set; }
public Nullable<byte> NUMERIC_PRECISION { get; set; }
public Nullable<short> NUMERIC_PRECISION_RADIX { get; set; }
public Nullable<int> NUMERIC_SCALE { get; set; }
public Nullable<short> DATETIME_PRECISION { get; set; }
public string CHARACTER_SET_CATALOG { get; set; }
public string CHARACTER_SET_SCHEMA { get; set; }
public string CHARACTER_SET_NAME { get; set; }
public string COLLATION_CATALOG { get; set; }
public string COLLATION_SCHEMA { get; set; }
public string COLLATION_NAME { get; set; }
public string DOMAIN_CATALOG { get; set; }
public string DOMAIN_SCHEMA { get; set; }
public string DOMAIN_NAME { get; set; }
}
控制器
public ActionResult Index()
{
List<XmlElement> elements = new List<XmlElement>();
XmlElement element1 = new XmlElement();
element1.ElementName = "element1";
element1.tableColumns = data.GetTableColumns("TABLENAME");
elements.Add(element1);
DataMappingViewModel viewitem = new DataMappingViewModel();
viewitem.XmlElements = elements;
viewitem.TableName = "TABLENAME";
return View(viewitem);
}
[HttpPost]
public ActionResult MapData(DataMappingViewModel model)
{
return View("Index",model);
}
查看
@model ExcelImportAPI.Models.DataMappingViewModel
@using System.Web.Mvc;
@{
ViewBag.Title = "title";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("MapData", "DataMapping", FormMethod.Post))
{
<h2>Data Mapping</h2>
for (var i = 0; i < Model.XmlElements.Count; i++)
{
@Html.HiddenFor(m => Model.XmlElements[i].ElementName)
@Model.XmlElements[i].ElementName
<td>
@Html.DropDownList("tableColumns", new SelectList(@Model.XmlElements[i].tableColumns, "COLUMN_NAME", "COLUMN_NAME"), "--Select a Value--")
</td>
}
<div class="modal-footer">
<input type="submit" name="btnSaveAndExit" value="Save and Exit" class="btn btn-default">
<input type="submit" name="btnSaveAndContinue" value="Save and Continue" class="btn btn-primary modal-btn">
</div>
}
您能否請您展示您的觀點? – JanR
剛剛添加....謝謝。 – Chaos
'tableColumns'是一個複雜的對象,您不能將一個