简体   繁体   English

在asp.net中为_layout.cshtml视图显示一条记录

[英]Displaying a single record in the asp.net for the _layout.cshtml view

I'm out of ideas, but I guess it's because I'm a noob in asp.net. 我没有主意,但是我想这是因为我是asp.net的菜鸟。 I have a MVC3 project and my idea was to have 2 sections: 我有一个MVC3项目,我的想法是有2个部分:

在此处输入图片说明

Section Main is for displaying tables and news and all the staff that changes when entering different pages. 主要部分用于显示表格和新闻以及进入不同页面时更改的所有人员。 Section Main_profile is for displaying profile info (name, email etc) for currently logged user. Main_profile部分用于显示当前登录用户的配置文件信息(名称,电子邮件等)。 Here is the problem. 这是问题所在。 I know I need to put the code for Main_profile displaying in the _Layout.cshtml, as I want that information to be shown all the time. 我知道我需要将Main_profile的代码显示在_Layout.cshtml中,因为我希望一直显示该信息。 I have tried this: 我已经试过了:

    <section id="main_profile">
        @Html.Action("Profile", "Person", new { name = User.Identity.Name })
    </section>

Profile is a method in my PersonController, which looks like this: Profile是我的PersonController中的方法,如下所示:

public ViewResult Profile(string name)
    {
        string person_n = name;
        return View(db.Persons.Where(s => s.Username.Equals(person_n)));
    }

At the end, there is a view for Profile: 最后,有一个Profile视图:

@model IEnumerable<Bachelor.Models.Person>
<h2>Your profile</h2>
<table border = "1">
<tr>
    <th>
        Username
    </th>
    <th>
        Birthday
    </th>
    <th>
        Education
    </th>
    <th>
        Email
    </th>
</tr>
@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Username)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Birthday)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Education)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Email)
    </td>
</tr>

But what I get is this "An unhandled exception of type 'System.StackOverflowException' occurred in Unknown Module." 但是我得到的是“未知模块中发生了'System.StackOverflowException'类型的未处理异常”。

Don't know if that may have something to do with it, but in the Main section, on some pages there is a table of records being displayed. 不知道这是否与它有关,但是在“主要”部分的某些页面上,有一个记录表正在显示。 What am I doing wrong here? 我在这里做错了什么?

Set your Layout to null in your partial. 在您的局部中将Layout设置为null。 What is doing is recursively calling itself: 正在做的事情是递归调用自己:

 @{ Layout = null; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC中_layout.cshtml中的布局 - Layout in _layout.cshtml in ASP.NET MVC 如何在Asp.net MVC中将值从部分视图传递到共享视图_Layout.cshtml? - How to pass value from partial view to shared view _Layout.cshtml in asp.net MVC? 将常见数据传递到ASP.Net MVC中的_Layout.cshtml中 - Passing common data into the _Layout.cshtml in ASP.Net MVC 将Bootstrap连接到ASP.NET _Layout.cshtml文件 - Connecting Bootstrap to ASP.NET _Layout.cshtml file 在 Layout.cshtml Asp.net 中调用模型时出错 - Error when call model in Layout.cshtml Asp.net 徽标未显示在ASP.net _layout.cshtml的导航栏中 - Logo not showing in navbar in ASP.net _layout.cshtml 在ASP.NET Core中的_Layout.cshtml中访问cookie - access cookie in _Layout.cshtml in ASP.NET Core 如何在 ASP.NET Core Razor Pages 项目的 _layout.cshtml 文件中使用 Razor 页面使用实体框架作为部分视图? - How to use Razor Page Using Entity Framework as a partial view in _layout.cshtml file in ASP.NET Core Razor Pages project? ASP.NET Core 中的翻译问题,通过 ASP.NET _Layout.cshtml 中的核心本地化 - Problem with translation in ASP.NET Core via ASP.NET Core localization in _Layout.cshtml ASP.NET,MVC,C#应用程序-为不同的视图修改_Layout.cshtml - ASP.NET, MVC, C# application - modify _Layout.cshtml for different Views
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM