部分视图();该名称在当前上下文中不存在
PartialView(); The name does not exist in the current context
所以我有点卡住了。我仍在学习所有这些东西,但我必须向我的应用程序添加一个 csv 解析器,它应该在我的警报页面上显示结果。如果我这样做
return PartialView(model, pin, tDate, stat);
它会告诉我 pin、tDate 和 stat 在当前上下文中不存在。如果我将它们取出,应用程序将 运行,但不会显示预期的结果。
我在 UserADInfoModel.cs
中声明了 pin、tDate 和 stat
这里是控制器:
public ActionResult _Alerts(UserADInfoModel model, List<string> groups)
{
DataRowCollection drColl = Core.GetAlerts(model);
ViewBag.Alerts = drColl;
var path = @"Exchange Migration data 10-25-17.csv";
using (TextFieldParser csvParser = new TextFieldParser(path))
{
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = true;
// Skip the row with the column names
csvParser.ReadLine();
// Read the lines
while (!csvParser.EndOfData)
{
string[] fields = csvParser.ReadFields();
string pin = fields[0];
string tDate = fields[2];
string stat = fields[6];
}
}
return PartialView(model, pin, tDate, stat);
}
这是视图
@if (@ViewBag.pin == Model.SAM)
{
<tr style="background-color : #ff3333; color: #ffffff">
<td style="padding-left :10px; padding-right: 10px;padding-top:2px; padding-bottom: 2px">
<p>Critical</p>
</td>
<td style="padding-left :10px; padding-right: 10px;padding-top:2px; padding-bottom: 2px">
<p>Exchange Migration</p>
</td>
<td style="padding-left :10px; padding-right: 10px;padding-top:2px; padding-bottom: 2px">
<p>Caller was set to migrate on (@ViewBag.tDate). The status of the migration is (@ViewBag.stat). Please contact Hypercare</p>
</td>
</tr>
}
@foreach (var x in ViewBag.Alerts)
{
var uClass = (x["Weight"].Contains("Warning")) ? "#ff8c1a, " : (x["Weight"].Contains("Critical")) ? "#ff3333" : "";
<tr @if (x["Weight"].Contains("Warning")) {
@MvcHtmlString.Create("style=\"background-color: #ff8c1a\"")
}
else if(x["Weight"].Contains("Critical")){
@MvcHtmlString.Create("style=\"background-color: #ff3333; color: #ffffff\"")
}>
我做错了什么? TIA
您在 while
范围内声明了 pin
、tDate
和 stat
。
决定是使用模型(推荐)还是ViewBag
传递数据:
public ActionResult _Alerts(UserADInfoModel model, List<string> groups)
{
DataRowCollection drColl = Core.GetAlerts(model);
ViewBag.Alerts = drColl;
var path = @"Exchange Migration data 10-25-17.csv";
using (TextFieldParser csvParser = new TextFieldParser(path))
{
// ...
while (!csvParser.EndOfData)
{
string[] fields = csvParser.ReadFields();
model.pin = fields[0];
model.tDate = fields[2];
model.stat = fields[6];
}
}
return PartialView(model);
}
_Alerts.cshtml:
@model UserADInfoModel
@if (@Model.pin == Model.SAM)
// ...
// ... @Model.tDate ... @Model.stat ...
所以我有点卡住了。我仍在学习所有这些东西,但我必须向我的应用程序添加一个 csv 解析器,它应该在我的警报页面上显示结果。如果我这样做
return PartialView(model, pin, tDate, stat);
它会告诉我 pin、tDate 和 stat 在当前上下文中不存在。如果我将它们取出,应用程序将 运行,但不会显示预期的结果。
我在 UserADInfoModel.cs
中声明了 pin、tDate 和 stat这里是控制器:
public ActionResult _Alerts(UserADInfoModel model, List<string> groups)
{
DataRowCollection drColl = Core.GetAlerts(model);
ViewBag.Alerts = drColl;
var path = @"Exchange Migration data 10-25-17.csv";
using (TextFieldParser csvParser = new TextFieldParser(path))
{
csvParser.CommentTokens = new string[] { "#" };
csvParser.SetDelimiters(new string[] { "," });
csvParser.HasFieldsEnclosedInQuotes = true;
// Skip the row with the column names
csvParser.ReadLine();
// Read the lines
while (!csvParser.EndOfData)
{
string[] fields = csvParser.ReadFields();
string pin = fields[0];
string tDate = fields[2];
string stat = fields[6];
}
}
return PartialView(model, pin, tDate, stat);
}
这是视图
@if (@ViewBag.pin == Model.SAM)
{
<tr style="background-color : #ff3333; color: #ffffff">
<td style="padding-left :10px; padding-right: 10px;padding-top:2px; padding-bottom: 2px">
<p>Critical</p>
</td>
<td style="padding-left :10px; padding-right: 10px;padding-top:2px; padding-bottom: 2px">
<p>Exchange Migration</p>
</td>
<td style="padding-left :10px; padding-right: 10px;padding-top:2px; padding-bottom: 2px">
<p>Caller was set to migrate on (@ViewBag.tDate). The status of the migration is (@ViewBag.stat). Please contact Hypercare</p>
</td>
</tr>
}
@foreach (var x in ViewBag.Alerts)
{
var uClass = (x["Weight"].Contains("Warning")) ? "#ff8c1a, " : (x["Weight"].Contains("Critical")) ? "#ff3333" : "";
<tr @if (x["Weight"].Contains("Warning")) {
@MvcHtmlString.Create("style=\"background-color: #ff8c1a\"")
}
else if(x["Weight"].Contains("Critical")){
@MvcHtmlString.Create("style=\"background-color: #ff3333; color: #ffffff\"")
}>
我做错了什么? TIA
您在 while
范围内声明了 pin
、tDate
和 stat
。
决定是使用模型(推荐)还是ViewBag
传递数据:
public ActionResult _Alerts(UserADInfoModel model, List<string> groups)
{
DataRowCollection drColl = Core.GetAlerts(model);
ViewBag.Alerts = drColl;
var path = @"Exchange Migration data 10-25-17.csv";
using (TextFieldParser csvParser = new TextFieldParser(path))
{
// ...
while (!csvParser.EndOfData)
{
string[] fields = csvParser.ReadFields();
model.pin = fields[0];
model.tDate = fields[2];
model.stat = fields[6];
}
}
return PartialView(model);
}
_Alerts.cshtml:
@model UserADInfoModel
@if (@Model.pin == Model.SAM)
// ...
// ... @Model.tDate ... @Model.stat ...