模型详细信息显示在 View 上的文本中 - 如何停止显示文本?
Model details showing in text on View - how do I stop the text showing?
我正在使用 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>
问题是由使用 @Model
而不是 @model
引起的 - 应归功于 Collen 以获取以下有助于解决此问题的引用:
If I recall correctly, the model type declaration at the top of your view should start with @model, not @Model, but I can't test that at the moment.
进一步测试后,@Model
向用户显示由控制器呈现给视图的模型的详细信息,后跟模型详细信息之后的任何字符串。
例如,在这个问题中,@Model BB2020MVC.Models.RaceNames;
将向用户呈现 System.Collections.Generic.List1[]BB2020MVC.Models.RaceNames;
;视图的其余部分将正确显示,因为视图将从 ViewBag
和呈现的模型中获取值。
@model
,然而,正确声明了模型,并没有显示模型细节,它还允许@Model
和@model
在你编程时正确显示正确的模型字段视图。
我正在使用 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>
问题是由使用 @Model
而不是 @model
引起的 - 应归功于 Collen 以获取以下有助于解决此问题的引用:
If I recall correctly, the model type declaration at the top of your view should start with @model, not @Model, but I can't test that at the moment.
进一步测试后,@Model
向用户显示由控制器呈现给视图的模型的详细信息,后跟模型详细信息之后的任何字符串。
例如,在这个问题中,@Model BB2020MVC.Models.RaceNames;
将向用户呈现 System.Collections.Generic.List1[]BB2020MVC.Models.RaceNames;
;视图的其余部分将正确显示,因为视图将从 ViewBag
和呈现的模型中获取值。
@model
,然而,正确声明了模型,并没有显示模型细节,它还允许@Model
和@model
在你编程时正确显示正确的模型字段视图。