我正在尝试使用Visual Studio 2019创建ASP.NET MVC应用,但是我在部分视图查询方面存在一些问题。
如果我在视图中组合查询并调用@Html.partial
,则它们将运行,否则,如果我在控制器中组合查询并创建局部视图,则当我调用@Html.partial
时,它们将无法正确运行。
关于性能或其他任何问题吗?我究竟做错了什么?
感谢您的帮助。
这里是代码:
((1)案件正在正常运行
查看:
@model IEnumerable<archea.Models.T_Anagrafica>
@Html.Partial("_Index", Model.Where(p => p.Cliente == true))
控制器:
// GET: T_Anagrafica
public ActionResult _Index()
{
return PartialView(db.T_Anagrafica.OrderBy(den => den.Denominazione).ToList());
}
((2)案例未运行
查看:
@model IEnumerable<archea.Models.T_Anagrafica>
@Html.Partial("_IndexClienti")
控制器:
// GET: T_Anagrafica
public ActionResult _IndexClienti()
{
return View(db.T_Anagrafica.Where(p => p.Cliente == true).OrderBy(den => den.Denominazione).ToList());
}
她的_IndexClienti代码:
@model IEnumerable<archea.Models.T_Anagrafica>
<h3>Clienti</h3>
<table class="table">
<tr>
<th class="small">
@Html.DisplayNameFor(model => model.IdAnagrafica)
</th>
<th>
@Html.DisplayNameFor(model => model.Denominazione)
</th>
<th>
@Html.DisplayNameFor(model => model.Indirizzo)
</th>
<th>
@Html.DisplayNameFor(model => model.CF)/<BR>
@Html.DisplayNameFor(model => model.PIVA)
</th>
<th>
@Html.DisplayNameFor(model => model.Tel)<BR>
@Html.DisplayNameFor(model => model.FAX)
</th>
<th>
@Html.DisplayNameFor(model => model.email)
</th>
<th>
@Html.DisplayNameFor(model => model.CodAnacf)
</th>
<th>
@Html.DisplayNameFor(model => model.Fornitore)
</th>
<th>
@Html.DisplayNameFor(model => model.Cliente)
</th>
<th>
@Html.DisplayNameFor(model => model.Ente)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td class="small">
@Html.DisplayFor(modelItem => item.IdAnagrafica)
</td>
<td>
@Html.DisplayFor(modelItem => item.Denominazione)
</td>
<td>
@Html.DisplayFor(modelItem => item.Indirizzo)<BR>
@Html.DisplayFor(modelItem => item.CAP) -
@Html.DisplayFor(modelItem => item.Citta)
(@Html.DisplayFor(modelItem => item.Provincia))
</td>
<td>
@Html.DisplayFor(modelItem => item.CF)<BR>
@Html.DisplayFor(modelItem => item.PIVA)
</td>
<td>
@Html.DisplayFor(modelItem => item.Tel)<br>
@Html.DisplayFor(modelItem => item.FAX)
</td>
<td>
@Html.DisplayFor(modelItem => item.email)
</td>
<td>
@Html.DisplayFor(modelItem => item.CodAnacf)
</td>
<td>
@Html.DisplayFor(modelItem => item.Fornitore)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cliente)
</td>
<td>
@Html.DisplayFor(modelItem => item.Ente)
</td>
<td>
<div class="btn-group">
<a href='@Url.Action("Edit", new { Controller = "T_Anagrafica", action = "Edit", id = item.IdAnagrafica })' class="btn btn-success">
<span class="glyphicon glyphicon-edit"></span>
</a>
<a href='@Url.Action("Details", new { Controller = "T_Anagrafica", action = "Details", id = item.IdAnagrafica })' class="btn btn-primary">
<span class="glyphicon glyphicon-list"></span>
</a>
<a href='@Url.Action("Delete", new { Controller = "T_Anagrafica", action = "Delete", id = item.IdAnagrafica })' class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</a>
</div>
</td>
</tr>
}
</table>