gpt4 book ai didi

c# - 显示TimeLine右侧的数据

转载 作者:太空宇宙 更新时间:2023-11-03 14:52:42 26 4
gpt4 key购买 nike

如何根据Candidate.Saving结果在时间线的左侧或右侧显示描述数据?如果是Candidate.Saving == true,它应该在左边,如果是Candidate.Saving==false,它应该在时间线的右边。我将在这里展示我的候选模型和我的 View 。

public class Candidate : BaseEntity
{
public int Id { get; set; }
public string Name { get; set; }
public int Number { get; set; }
public string ProfileText { get; set; }
public Byte[] CV { get; set; }
public string CVNAME { get; set; }
public List<Profile> ProfileList { get; set; }
public String Description { get; set; }
public Boolean Saving { get; set; }
public string Title { get; set; }
public DateTime DateOfDescription { get; set; }
}

这是我的看法:

@model HCCBPOHR.Data.Candidate

@{
ViewData["Title"] = "CandidateHistory";
}

<h2>Canidate - @Model.Name</h2>

<label>History</label>
<hr />

<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-clock-o fa-fw"></i> History Of @Model.Name
</div>

@foreach (var Description in Model.Description)
{
@if (Model.Saving == true)
{
<ul>
<li class="timeline">
<div class="timeline-badge">
<i class="fa fa-check"></i>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Title</h4>
<p>
<small class="text-muted"><i class="fa fa-clock-o"></i> @Model.DateOfDescription.ToShortDateString()</small>
</p>
</div>
<div class="timeline-body">
<p>@Model.Description</p>
</div>
</div>
</li>
</ul>

}
@if (Model.Saving == false)
{

<ul>
<li class="timeline-inverted">
<div class="timeline-badge">
<i class="fa fa-check"></i>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Title</h4>
<p>
<small class="text-muted"><i class="fa fa-clock-o"></i> @Model.DateOfDescription.ToShortDateString()</small>
</p>
</div>
<div class="timeline-body">
<p>@Model.Description</p>
</div>
</div>
</li>
</ul>

}

}
</div>

@*<div class="panel-body">
<ul class="timeline">
<li>
<li class="timeline-inverted">
Isto é para inverter o lado
<div class="timeline-badge">
<i class="fa fa-check"></i>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Title</h4>
<p>
<small class="text-muted"><i class="fa fa-clock-o"></i> @Model.DateOfDescription.ToShortDateString()</small>
</p>
</div>
<div class="timeline-body">
<p>@Model.Description</p>
</div>
</div>
</li>
</ul>
</div>
</div>*@



<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@Model.Saving"> Add History Description</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<form asp-action="CandidateHistory">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Title" class="control-label"></label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<input asp-for="Description" class="form-control" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<label>Selects</label>
<select asp-for="Saving" class="form-control">
<option value="false">Candidate </option>
<option value="true">Hitachi</option>s
</select>
</div>
<div class="form-group">
<label asp-for="DateOfDescription" class="form-group"></label>
<input asp-for="DateOfDescription" class="form-group" />
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

</div>
</div>
</div>
</div>

我尝试做的事情:我试图制作一个 foreach 方法,其中一侧取决于 Candidate.Saving,但结果是这样的:

enter image description here

我已经设法修复它。我是这样做的:

    <div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-clock-o fa-fw"></i> History Of @Model.Name
</div>
<div class="panel-body">
@if (Model.Saving == true)
{
<ul class="timeline">
<li class="timeline">
<div class="timeline-badge">
<i class="fa fa-check"></i>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Title</h4>
<p>
<small class="text-muted"><i class="fa fa-clock-o"></i>
@Model.DateOfDescription.ToShortDateString()</small>
</p>
</div>
<div class="timeline-body">
<p>@Model.Description</p>
</div>
</div>
</li>
</ul>
}
@if (Model.Saving == false)
{
<ul class="timeline">
<li class="timeline-inverted">
<div class="timeline-badge">
<i class="fa fa-check"></i>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Title</h4>
<p>
<small class="text-muted"><i class="fa fa-clock-o"></i> @Model.DateOfDescription.ToShortDateString()</small>
</p>
</div>
<div class="timeline-body">
<p>@Model.Description</p>
</div>
</div>
</li>
</ul>
}
</div>
</div>

I only have on doubt right now, to be able to add more than one Description for the candidate I should Create a list off Descriptions and do a foreach method in the view right?

现在我的 Controller 看起来像这样:

public IActionResult CandidateHistory(int Id)
{

using (var applicationcontext = new ApplicationContext())
{
var candidate = applicationcontext.Candidates.Where(s => s.Id.Equals(Id)).SingleOrDefault();
if (candidate == null)
{
return NotFound();
}

Candidate candidates = new Candidate();
candidates.DescriptionList.Add(candidate);
candidates.DescriptionList.Add(new Candidate { Description = candidate.Description });
candidates.DescriptionList.Add(new Candidate { Title = candidate.Title });
candidates.DescriptionList.Add(new Candidate { DateOfDescription = candidate.DateOfDescription });
candidates.DescriptionList.Add(new Candidate { Saving = candidate.Saving });
applicationcontext.Candidates.Add(candidates);
return View();
}
}
[HttpPost, ActionName("CandidateHistory")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> CandidateHistoryPost(int? id, Candidate candidatelist)
{
if (id == null)
{
return NotFound();
}
using (var context = new ApplicationContext())
{
var candidateUpdate = await context.Candidates.SingleOrDefaultAsync(s => s.Id == id);
if (await TryUpdateModelAsync<Candidate>(candidateUpdate, "", s => s.Description, s => s.Title, s => s.DateOfDescription, s => s.Saving))
{
try
{
await context.SaveChangesAsync();
return RedirectToAction(nameof(CandidateHistory));
}
catch (DbUpdateException /* ex */)
{
//Log the error (uncomment ex variable name and write a log.)
ModelState.AddModelError("", "Unable to save changes. " +
"Try again, and if the problem persists, " +
"see your system administrator.");
}
}
return View(candidateUpdate);
}
}

我正在尝试将 Candidate.DescriptionList 输出到 CandidateHistory View ,这样我就可以将所有描述、描述标题、日期和“保存”保存到该列表中,这样我就可以使用 foreach 方法输出所有该用户的描述。但是现在我有这个错误:

System.NullReferenceException: 'Object reference not set to an instance of an object.

HCCBPOHR.Data.Candidate.DescriptionList.get returned null.`

最佳答案

我已经设法修复了它。我是这样做的:

    <div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-clock-o fa-fw"></i> History Of @Model.Name
</div>
<div class="panel-body">
@if (Model.Saving == true)
{
<ul class="timeline">
<li class="timeline">
<div class="timeline-badge">
<i class="fa fa-check"></i>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Title</h4>
<p>
<small class="text-muted"><i class="fa fa-clock-o"></i>
@Model.DateOfDescription.ToShortDateString()</small>
</p>
</div>
<div class="timeline-body">
<p>@Model.Description</p>
</div>
</div>
</li>
</ul>
}
@if (Model.Saving == false)
{
<ul class="timeline">
<li class="timeline-inverted">
<div class="timeline-badge">
<i class="fa fa-check"></i>
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">Title</h4>
<p>
<small class="text-muted"><i class="fa fa-clock-o"></i> @Model.DateOfDescription.ToShortDateString()</small>
</p>
</div>
<div class="timeline-body">
<p>@Model.Description</p>
</div>
</div>
</li>
</ul>
}
</div>
</div>

I only have on doubt right now, to be able to add more than one Description for the candidate I should Create a list off Descriptions and do a foreach method in the view right?

关于c# - 显示TimeLine右侧的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51133711/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com