C# 视图和局部视图之间的对齐问题
我想知道是否有人可以帮我解决一些对齐问题。我有一个局部视图,当我在其中循环时,我想把它放在一个表中 我尝试了两种方法C# 视图和局部视图之间的对齐问题,c#,ajax,asp.net-mvc,razor,twitter-bootstrap-3,C#,Ajax,Asp.net Mvc,Razor,Twitter Bootstrap 3,我想知道是否有人可以帮我解决一些对齐问题。我有一个局部视图,当我在其中循环时,我想把它放在一个表中 我尝试了两种方法 使用两个单独的表(一个在主视图中,一个在局部视图中) 将表放在主视图中,然后仅将行放在部分视图中,则不会成功 在我的模型中,每个循环之间都会有额外的换行符(这是我想使用表来尝试停止这些额外的空行的主要原因) 我已经更新了现在发生的事情,包括提出的建议。我仍然有问题 当我单击AddNew时,问题变得非常具体。新行不会进入表中,因为表已在on page load中创建,是否可以在更新
<div id="editorRows">
<div class="row text-center ">
@Html.ActionLink("Add New Line", "BlankEditorRow", null, new { id = "addItem", @class = "btn blue" })
<input type="submit" value="Save Changes" class="btn blue" />
</div>
<table class="table" style="border: none;" width="70">
<tr>
<th>StockCode</th>
<th class="tg-031e">Description</th>
<th>Qty</th>
<th>Price</th>
<th>Net</th>
<th>Tax</th>
<th>Gross</th>
<th>Remove</th>
</tr>
<tr>
@if (Model.OrderLines != null)
{
foreach (var item in Model.OrderLines)
{
Html.RenderPartial("OrderLinesEditorRow", item);
}
}
</tr>
</table>
</div>
@ActionLink(“添加新行”、“BlankEditorRow”、null、New{id=“addItem”、@class=“btn blue”})
股票代码
描述
数量
价格
网
税
粗俗的
去除
@if(Model.OrderLines!=null)
{
foreach(Model.OrderLines中的var项)
{
RenderPartial(“OrderLinesEditorRow”,item);
}
}
局部视图:
@using HtmlHelpers.BeginCollectionItem
@model MyModel.Models.OrderLines
<style>
input.Width {
width: 5em;
}
</style>
<div class="editorRow">
<script>
$("a.deleteRow").live("click", function () {
$(this).parents("div.editorRow:first").remove();
return false;
});
$(document).ready(function () {
$('.selectpicker').selectpicker({
liveSearch: true,
showSubtext: true
});
});
</script>
@using (Html.BeginCollectionItem("OrderLines"))
{
<td>
@Html.HiddenFor(model => model.Itemid, new { size = 4 })
@Html.DropDownList("StockCode",
new SelectList(ViewBag.StockCodeList, "Value", "Text"),
new
{
@class = "form-control selectpicker",
@Value = @Model.Description,
onchange = "this.form.submit();",
data_show_subtext = "true",
data_live_search = "true"
})
</td>
<td>
@Html.DropDownListFor(x => x.StockCode,
(IEnumerable<SelectListItem>)ViewBag.AllStockList,
new
{
@class = "form-control selectpicker",
@Value = @Model.Description,
onchange = "this.form.submit();",
data_show_subtext = "true",
data_live_search = "true"
})
</td>
<td>
@Html.EditorFor(model => model.QtyOrder, new { htmlAttributes = new { @class = "form-control Width", @Value = @Model.QtyOrder } })
</td>
<td>
@Html.EditorFor(model => model.UnitPrice, new { htmlAttributes = new { @class = "form-control Width", @Value = @Model.UnitPrice } })
</td>
<td>
@Html.EditorFor(model => model.NetAmount, new
{
htmlAttributes = new { @class = "form-control Width", @Value = @Model.NetAmount }
})
</td>
<td>
@Html.EditorFor(model => model.TaxAmount, new { htmlAttributes = new { @class = "form-control Width", @Value = @Model.TaxAmount } })
</td>
<td>
@Html.EditorFor(model => model.FullNetAmount, new { htmlAttributes = new { @class = "form-control Width", @Value = @Model.FullNetAmount } })
</td>
<td>
<a href="#" class="deleteRow btn blue">Remove</a>
</td>
}
</div>
@使用HtmlHelpers.BeginCollectionItem
@模型MyModel.Models.OrderLines
输入宽度{
宽度:5em;
}
$(“a.deleteRow”).live(“单击”,函数(){
$(this).parents(“div.editorRow:first”).remove();
返回false;
});
$(文档).ready(函数(){
$('.selectpicker')。selectpicker({
liveSearch:没错,
显示潜台词:真
});
});
@使用(Html.BeginCollectionItem(“订单行”))
{
@Html.HiddenFor(model=>model.Itemid,新的{size=4})
@Html.DropDownList(“股票代码”,
新建选择列表(ViewBag.StockCodeList,“值”、“文本”),
新的
{
@class=“表单控件选择器选择器”,
@Value=@Model.Description,
onchange=“this.form.submit();”,
数据\u显示\u subtext=“true”,
数据\u实时\u搜索=“真实”
})
@Html.DropDownListFor(x=>x.StockCode,
(IEnumerable)ViewBag.AllStockList,
新的
{
@class=“表单控件选择器选择器”,
@Value=@Model.Description,
onchange=“this.form.submit();”,
数据\u显示\u subtext=“true”,
数据\u实时\u搜索=“真实”
})
@EditorFor(model=>model.QtyOrder,new{htmlAttributes=new{@class=“form control Width”,@Value=@model.QtyOrder}})
@EditorFor(model=>model.UnitPrice,new{htmlAttributes=new{@class=“form control Width”,@Value=@model.UnitPrice}})
@Html.EditorFor(model=>model.NetAmount,新
{
htmlAttributes=new{@class=“form control Width”,@Value=@Model.NetAmount}
})
@EditorFor(model=>model.taxantum,new{htmlAttributes=new{@class=“form control Width”,@Value=@model.taxantum}})
@EditorFor(model=>model.FullNetAmount,new{htmlAttributes=new{@class=“form control Width”,@Value=@model.FullNetAmount})
}
您可以使用两个tr,我的意思是两个表行而不是一个,并在特定视图中按行构造。您只使用了1个tr,在该行中添加了2个下拉列表或文本框。之后,您可以检查您的html是否是有效的html5。链接
另外,从主视图中,只需启动表标记..然后启动foreach..,它将只包含行..,最后关闭表标记。问题是你们的桌子太多了。我想说它只能合并到一个表中
主视图:表格以标题开头
…每一项
……仅带表格行的局部视图
……foreach的结尾
主视图:关闭表您可以使用两个tr,我的意思是两个表行而不是一个,并在特定视图中按行构造。您只使用了1个tr,在该行中添加了2个下拉列表或文本框。之后,您可以检查您的html是否是有效的html5。链接 另外,从主视图中,只需启动表标记..然后启动foreach..,它将只包含行..,最后关闭表标记。问题是你们的桌子太多了。我想说它只能合并到一个表中 主视图:表格以标题开头 …每一项 ……仅带表格行的局部视图 ……foreach的结尾
主视图:关闭表在
<table class="inventory">
<thead>
<tr>
<th width="180"><span>Code</span></th>
<th width="265"><span>Description</span></th>
<th><span>Price</span></th>
<th><span>Quantity</span></th>
<th><span>Discount %</span></th>
<th><span>Discount Amt</span></th>
<th><span>Net £</span></th>
<th><span>Tax %</span></th>
<th><span>VAT Amt</span></th>
</tr>
</thead>
@{
if (Model.OrderLines == null)
{
Model.OrderLines = new List<Accounts.Models.OrderLines>();
Accounts.Models.OrderLines Line = new Accounts.Models.OrderLines();
Line.CustomerID = Model.CustomerID;
Model.OrderLines.Add(Line);
}
foreach (var item in Model.OrderLines)
{
Html.RenderPartial("orderline", item);
}
}
</table>
代码
描述
价格
量
折扣%
贴现金额
净额
税%
增值税金额
@{
if(Model.OrderLines==null)
{
Model.OrderLines=新列表();
Accounts.Models.OrderLines=新Accounts.Models.OrderLines();
Line.CustomerID=Model.CustomerID;
Model.OrderLines.Add(行);
@using HtmlHelpers.BeginCollectionItem
@{
Layout = "";
}
@using (Html.BeginCollectionItem("OrderLines"))
{
<tbody>
<tr>
<td>
<a class="cut">-</a><span contenteditable>
@Html.DropDownList("StockCode", new SelectList(ViewBag.StockCodeList, "Value", "Text"),
new
{
@class = "form-control selectpicker",
@Value = @Model.Description,
onchange = "this.form.submit();",
data_show_subtext = "true",
data_live_search = "true"
})
</span>
</td>
<td><span contenteditable>
@Html.DropDownList("StockCode", new SelectList(ViewBag.AllStockList, "Value", "Text"),
new
{
@class = "form-control selectpicker ",
onchange = "this.form.submit();",
data_show_subtext = "true",
data_live_search = "true"
})
</span></td>
<td><span data-prefix>$</span><span contenteditable>150.00</span></td>
<td><span contenteditable>4</span></td>
<td><span contenteditable>0</span></td>
<td><span contenteditable>0.00</span></td>
<td><span contenteditable>0.00</span></td>
<td><span contenteditable>0</span></td>
<td><span data-prefix>$</span><span>0.00</span></td>
</tr>
</tbody>
}