Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

c# - Model details showing in text on View - how do I stop the text showing?

I am working in MVC, chtml and C# and slowly making progress on the project that I am working on - however, the details of the model is showing at the top of the view as System.Collections.Generic.List1 and cannot find why it should do so.

The Rest of the view is working fine.

How to sort this issue?

Top of the View:

    @Model BB2020MVC.Models.RaceNames;


<div><h2>All Races</h2></div> 

Partial View - Navigation Bar:

<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>

And the Layout

<!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>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Issue was caused by using @Model instead of @model - Credit should go to Collen for the following quote that assisted with this question:

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.

Upon testing further, @Model presents the user with the details of the model that was presented to the View by the Controller followed by the string of anything that was after the model detail.

For example, in this question, @Model BB2020MVC.Models.RaceNames; would present System.Collections.Generic.List1[]BB2020MVC.Models.RaceNames; to the user; the rest of the View would display properly as the View would pick up values from ViewBag and the presented Model.

@model, however, declares the model correctly and does not show the model details, it also allows @Model and @model to correctly display the correct model fields when you are programming the View.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...