[英]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.