我写了一个asp.net mvc的小界面,但在添加界面的表格处卡住了,想请教一下这个输入该怎么写。数据库是MongoDB
这是我定义的Model
public class DataSource { public ObjectId id { get; set; } [Display(Name = "数据源名称")] public string DataSourceName { get; set; } [Display(Name = "数据源描述")] public string DataSourceDescribe { get; set; } [Display(Name = "所属子系统")] public string Subordinatesubsystem { get; set; } [Display(Name = "是否启用")] public bool Enable { get; set; } public List<DataStructure> datastructureList { get; set; } } public class DataStructure { public ObjectId id { get; set; } [Display(Name = "字段")] public string DataStructurefield { get; set; } [Display (Name ="类型")] public string DataStructuretype { get; set; } [Display (Name ="描述")] public string DataStructuredescribe { get; set; } }
这是添加界面的代码
<h2>添加</h2> <script src="~/Scripts/AddAndRemove.js"></script> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>TheDataSource</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.DataSourceName, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.DataSourceName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.DataSourceName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.DataSourceDescribe, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.DataSourceDescribe, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.DataSourceDescribe, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Subordinatesubsystem, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Subordinatesubsystem, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Subordinatesubsystem, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Enable, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.CheckBoxFor(model => model.Enable, new { @class = "checkBox" }) </div> </div> <div> <table border="1" style="text-align:center;border-collapse:collapse" id="myTable"> <tr> <th width=100>字段</th> <th width=100>类型</th> <th width=100>描述</th> </tr> <tbody> @*@foreach(var item in Model) {*@ <tr> <td> @Html.EditorFor(model => model.Subordinatesubsystem, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Subordinatesubsystem, "", new { @class = "text-danger" }) </td> <td> @Html.EditorFor(model => model.Subordinatesubsystem, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Subordinatesubsystem, "", new { @class = "text-danger" }) </td> <td> @Html.EditorFor(model => model.Subordinatesubsystem, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Subordinatesubsystem, "", new { @class = "text-danger" }) </td> <td > <input type="hidden" id="reC" value="1" /> <input type="button" class="btn btn-default" value="添加" onclick="addRows();"> <a class="btn btn-default" onclick="saveTableValue()">表格数据</a> </td> </tr> @*}*@ </tbody> </table> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="添加" class="btn btn-default" /> </div> </div> </div> } <div> @Html.ActionLink("返回列表", "Index") </div> @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
js文件
function addRows() { //记录总共添加几行 document.getElementById("reC").value = parseInt(document.getElementById("reC").value) + 1;//获取中的行数 //添加一行 var i = parseInt(myTable.rows.length); var newTr = myTable.insertRow(); //添加列 var newTd0 = newTr.insertCell(); var newTd1 = newTr.insertCell(); var newTd2 = newTr.insertCell(); var newTd3 = newTr.insertCell(); //设置列内容和属性 newTd0.innerHTML = '<input type="text" id="field' + i + '_field' + i + '" class = "form-control" title="字段" value="" />'; newTd1.innerHTML = '<input type="text" id="txttype' + i + '_type" class = "form-control" title="类型" value=""/>'; newTd2.innerHTML = '<input type="text" id="txtdescribe' + i + '_describe" class = "form-control" title="描述" value=""/>'; newTd3.innerHTML = '<input type="submit" class="btn btn-default" value="删除该行" onclick="deleRow()" id="btnDele' + i + '" />'; // saveTableValue();//保存值 return false; } //删除一行 function deleRow() { //获得行索引 //两个parentElement分别是TD和TR,rowIndex是TR的属性 var cGetRow = window.event.srcElement.parentElement.parentElement.rowIndex; //alert("点击了第" + cGetRow); myTable.deleteRow(cGetRow); // saveTableValue();//保存值 return false; }
我想问一下黄色部分该怎么写,求详解,求代码。