我遇到了错误的例外情况
我是新学习的asp.net core,我得到了一个错误:
我一直在搜索解决方案i Internet,但没有得到任何结果。谁能帮我吗?这是我的代码:
details.cshtml
@model SixthApp.Models.Customer
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>Customer</h4>
<p>@ViewData["data"]</p>
<hr />
<dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.CustomerId)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.CustomerId)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Name)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Address)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Address)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.MobileNo)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.MobileNo)
</dd>
</dl>
</div>
<div>
@Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
<a asp-action="Index">Back to List</a>
</div>
这是customercontroller.cs中的详细方法
public IActionResult Details(int? Id)
{
var DataCustomer = _conn.tabel_customer.Where(c => c.CustomerId == Id).ToList();
return View(DataCustomer);
}
i'm newly learning ASP.net Core and i got this error :
I have been searching the solution i internet but didn't get any result. Can anyone help me? this is my code:
Details.cshtml
@model SixthApp.Models.Customer
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>Customer</h4>
<p>@ViewData["data"]</p>
<hr />
<dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.CustomerId)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.CustomerId)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Name)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Address)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Address)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.MobileNo)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.MobileNo)
</dd>
</dl>
</div>
<div>
@Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
<a asp-action="Index">Back to List</a>
</div>
this is detail method in CustomerController.cs
public IActionResult Details(int? Id)
{
var DataCustomer = _conn.tabel_customer.Where(c => c.CustomerId == Id).ToList();
return View(DataCustomer);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的视图需求是
模型
,您在操作中返回视图的内容是list
尝试以下代码:
The type your view needs is a
model
, and what you return to the view in your action is alist
Try below code:
您正在返回对象列表,并查看期望一个对象。
您应该,要么将控制器更改为这样的东西,要返回单个对象:
或将模型更改为
@model iEnumerable&lt; sixthapp.models.models.customer&gt;
,并在视图上循环槽以显示所有对象从控制器...You are returning list of objects, and view expects a single object.
You should, either change your controller to something like this, to return single object:
or change model to
@model IEnumerable<SixthApp.Models.Customer>
and loop trough it on a view to show all objects you got from controller....