我正在MVC、chtml和C#中工作,并在我正在进行的项目上缓慢地取得进展--然而,模型的细节以System.Collections.Generic.List1的形式显示在视图的顶部,无法找到为什么要这样做。
视图的其余部分运行良好。
如何解决这个问题?
视图顶部:
@Model BB2020MVC.Models.RaceNames;
<div><h2>All Races</h2></div> 部分视图-导航栏:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Main")</li>
<li>@Html.ActionLink("Base Teams", "Index", "BaseTeams")</li>
<li>@Html.ActionLink("Rules", "Index", "BaseRules")</li>
<li>@Html.ActionLink("Rosters", "Index", "Rosters")</li>
</ul>
</div>
</div>
</div>以及布局
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
@{Html.RenderAction(actionName: "Navbar", controllerName: "Main");}
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>发布于 2021-01-01 20:22:12
问题是使用@Model而不是@model引起的-- Credit应该转到Collen那里,以获得以下有助于解决这个问题的引用:
--如果我没记错,视图顶部的模型类型声明应该从@ model开始,而不是@model,但目前我不能测试它。
进一步测试后,@Model会向用户提供由Controller提交给视图的模型的详细信息,后面是模型细节之后的字符串。
例如,在这个问题中,@Model BB2020MVC.Models.RaceNames;将向用户呈现System.Collections.Generic.List1[]BB2020MVC.Models.RaceNames;;视图的其余部分将正确显示,因为视图将从ViewBag和提供的模型中获取值。
然而,@model正确声明了模型,没有显示模型细节,它还允许@Model和@model在编写视图时正确显示正确的模型字段。
https://stackoverflow.com/questions/65523607
复制相似问题