我正在为内部网站构建一个相当标准的razor / c#页面。它基本上是一个为db查询提供有效参数的查询的包装器。
该页面在构建时在Asp_Web _ ?????。cshtml中生成错误。对于我的生活,我找不到错误。下面包含页面来源
@{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "ABC Floor Limits";
}
<hgroup class="title">
<h1>@Page.Title.</h1>
<h2>Adjust.</h2>
</hgroup>
@{
var DbCustom = Database.Open("Online_Ctrack6_Custom");
var DbCustLogs = Database.Open("Online_CustLogs");
int vehicleId = -1;
string currentAction;
if(IsPost)
{
vehicleId = Request.Form["vehicleId"].AsInt();
string applianceName = Request.Form["applianceName"];
int floorHours = Request.Form["hours"].AsInt();
DateTime? dateToParse;
DateTime dateTaken;
string result = "";
if (string.IsNullOrEmpty(Request.Form["dateTaken"]) == false)
{
var dtValue = new DateTime();
if (DateTime.TryParse(Request.Form["dateTaken"], out dtValue))
{
dateToParse = dtValue;
}
else
{
dateToParse = null;
}
}
else
{
dateToParse = null;
}
currentAction = Request.Form["action"];
if (currentAction == "updateHours")
{
try
{
dateTaken = (DateTime)dateToParse;
result = doProcessHoursForm(DbCustLogs, vehicleId, applianceName, dateTaken, floorHours);
}
catch (InvalidDataException ex)
{
@:<div class="error">@ex.Message</div>
}
catch (ArgumentNullException ex)
{
@:<div class="error">@ex.ParamName cannot be null.<br />@ex.Message @ex.ParamName</div>
}
finally
{
@:<div class="result">@result</div>
}
}
}
List<SelectListItem> listVehicles = null;
try
{
listVehicles = doCreateVehicleList(DbCustom, vehicleId);
}
catch (Exception ex)
{
@:<div class="error">@ex.Message<br />@ex.InnerException.Message</div>
}
string floorSql = "SELECT [NodeId],[PrimaryPropertyValue],[ID],[PumpADurationSec],[PumpAFloorSec],[PumpAFloorDate],[PumpATotalSec],[PumpBDurationSec],[PumpBFloorSec],[PumpBFloorDate],[PumpBTotalSec],[VacuumDurationSec],[VacuumFloorSec],[VacuumFloorDate],[VacuumTotalSec] FROM [Ctrack6_Custom].[dbo].[vwVeoliaRunningTotals] ORDER BY [Id]";
var floorGrid = new WebGrid(source: DbCustom.Query(floorSql), canPage: false, ajaxUpdateContainerId: "floorGrid");
}
<div class="section">
<h3>Current Floor Values</h3>
<p>This table lists the current floor values for ABC . The values are saved internally as a number of seconds.</p>
@floorGrid.GetHtml(
tableStyle: "VeoliaFloorTable",
headerStyle: "columnHead",
alternatingRowStyle: "altRow",
columns: floorGrid.Columns(
floorGrid.Column(columnName: "NodeId", header: @Functions.Sorter("NodeId", "Node Id", floorGrid)),
floorGrid.Column(columnName: "Id", header: @Functions.Sorter("Id", "Vehicle", floorGrid)),
floorGrid.Column(columnName: "PumpAFloorSec", header: @Functions.Sorter("PumpAFloorSec", "Pump A Floor Sec", floorGrid), style: "alignRight"),
floorGrid.Column(columnName: "PumpAFloorDate", header: @Functions.Sorter("PumpAFloorDate", "Pump A Floor Date", floorGrid), style: "nowrap"),
floorGrid.Column(columnName: "PumpBFloorSec", header: @Functions.Sorter("PumpBFloorSec", "Pump B Floor Sec", floorGrid), style: "alignRight"),
floorGrid.Column(columnName: "PumpBFloorDate", header: @Functions.Sorter("PumpBFloorDate", "Pump B Floor Date", floorGrid), style: "nowrap"),
floorGrid.Column(columnName: "VacuumFloorSec", header: @Functions.Sorter("VacuumFloorSec", "Vacuum Floor Sec", floorGrid), style: "alignRight"),
floorGrid.Column(columnName: "VacuumFloorDate", header: @Functions.Sorter("VacuumFloorDate", "Vacuum Floor Date", floorGrid), style: "nowrap")
)
);
</div>
<div class="section">
<h3>Update Floor Limits</h3>
<p>This form allows you to update the floor limit specified for an appliance mounted on a vehicle.</p>
<form method="post">
<input type="hidden" name="username" value="@WebSecurity.CurrentUserName" />
<input type="hidden" name="action" value="updateHours" />
<label for="selectVehicleControl">Choose Geozone:</label>
@Html.DropDownList("vehicleId", listVehicles)
<label for="selectApplianceControl">Choose Appliance:</label>
<select name="applianceName" id="selectApplianceControl">
<option value="-1">Choose an Appliance</option>
<option value="Pump A">Pump A</option>
<option value="Pump B">Pump B</option>
<option value="Vacuum">Vacuum</option>
</select>
<label for="inputHoursText">Hour Reading:</label>
<input name="hours" type="number" id="inputHoursText" min="0" max="9999999" size="7" required="required" />
<span style="font-size:small">This will be converted into seconds</span>
<br />
<label for="dateTakenControl">Date Taken:</label>
<input name="dateTaken" class="datetimefield" type="datetime" id="dateTakenControl" maxlength="19" required="required" />
<br />
<input type="submit" value="Update Hour Reading" />
</form>
</div>
@{
public string doProcessHoursForm(Database DbCustLogs, int vehicleId, string applianceName, DateTime dateTaken, int floorHours)
{
int floorSeconds = floorHours * 3600;
string sqlHoursUpdate = "exec sp_Veolia_update_floor_limit @0, @1, @2, @3";
if(vehicleId != null && applianceName != null && dateTaken != null && floorSeconds != null)
{
var result = DbCustLogs.Execute(sqlHoursUpdate, vehicleId, applianceName, dateTaken.ToString("yyyy-MM-dd HH:mm:ss"), floorSeconds);
if ( result != 1)
{
throw new InvalidDataException("Operation should only affect one record");
}
else
{
return result + " row(s) changed";
}
}
else
{
string nullArg = "";
if (vehicleId == null) { nullArg += "vehicleId,";}
if (applianceName == null) { nullArg += "applianceName,"; }
if (dateTaken == null) { nullArg += "dateTaken,"; }
if (floorSeconds == null) { nullArg += "floorSeconds,"; }
if (nullArg.Length > 1) { nullArg = nullArg.TrimEnd(','); }
throw new ArgumentNullException(nullArg, "Argument cannot be null");
}
return "An error ocured";
}
public List<SelectListItem> doCreateVehicleList(Database db, int vehicleId)
{
var sqlVehicles = "SELECT NodeId, Id as VehicleName FROM vwVeoliaNodes ORDER BY Id";
List<SelectListItem> listTemp = new List<SelectListItem>();
listTemp.Add(new SelectListItem
{
Text = "Select a Vehicle",
Value = "-1",
Selected = false
});
try
{
foreach (var item in db.Query(sqlVehicles))
{
if (item.NodeId == vehicleId)
{
listTemp.Add(new SelectListItem
{
Text = item.VehicleName,
Value = item.NodeId.ToString(),
Selected = true
});
}
else
{
listTemp.Add(new SelectListItem
{
Text = item.VehicleName,
Value = item.NodeId.ToString(),
Selected = false
});
}
}
}
catch (Exception ex)
{
throw new Exception("Exception occurred building Vehicle List", ex);
}
return listTemp;
}
}
错误详情如下:
错误号: 1
错误消息:}预期
文件: c:\ Users \ Lukem \ AppData \ Local \ Temp \ Temporary ASP.NET Files \ root \ 53d555f7 \ b262e6b6 \ App_Web_abcfloor.cshtml.cdcab7d2.abupdzvs.0.cs
行: 760
tempfile中的错误是EndContext引用:
BeginContext("~/VeoliaFloor.cshtml", 5970, 36, true);
WriteLiteral(" />\r\n </form>\r\n </div>\r\n\r\n");
EndContext("~/VeoliaFloor.cshtml", 5970, 36, true);
我已经安装了颜色匹配{}工具来帮助您。只有在编译到临时文件时,页面似乎没有问题。这让我很生气。
答案 0 :(得分:0)
这是因为您在声明方法的部分中缺少@functions
关键字。