[英]Directing user to another page in ASP.Net MVC application leads to syntax error in auto-generated code
Snippet from my _layout.cshtml file我的 _layout.cshtml 文件中的片段
<body>
<!--
NAVBAR
-->
<div class="navBar">
<input id="homeButton" type="submit" name="homeButton" value="Home"/>
<input id="toolsButton" type="submit" name="toolsButton" value="Tools"/>
<input id="contactButton" type="submit" name="contactButton" value="Contact Me"/>
<input id="supportButton" type="submit" name="supportButton" value="Support"/>
<input id="aboutButton" type="submit" name="aboutButton" value="About"/>
</div><!--TODO: STYLE THESE -->
<script>
const homeButton = document.getElementById("homeButton");
const toolsButton = document.getElementById("toolsButton");
const contactButton = document.getElementById("contactButton");
const supportButton = document.getElementById("supportButton");
const aboutButton = document.getElementById("aboutButton");
homeButton.addEventListener("click", () => {
window.location.href = "/";
});
toolsButton.addEventListener("click", () => {
window.location.href = "/Tools/Index"; // "/Tools" doesn't work either
});
contactButton.addEventListener("click", () => {
window.location.href = "/";
});
supportButton.addEventListener("click", () => {
window.location.href = "/";
});
aboutButton.addEventListener("click", () => {
window.location.href = "/";
});
</script>
The error generated when button clicked单击按钮时产生的错误
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1003: Syntax error, '>' expected
Source Error:
Line 29:
Line 30:
Line 31: public class _Page_Views_Tools_Index_cshtml : System.Web.Mvc.WebViewPage<LgbtqWebsiteNoDb.Models.Tool;> {
Line 32:
Line 33: #line hidden
Source File: c:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\App_Web_index.cshtml.f024d85f.citsmrxd.0.cs Line: 31
Detailed compiler output详细编译output
C:\Program Files (x86)\IIS Express> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\87f9e4d5\000e9c93_3d27cf01\System.Web.Optimization.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\App_global.asax.ewmqttqt.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\b5be25e0\003c87e2_1a87d401\System.Web.WebPages.Razor.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\77f8a528\001bc110_4318cf01\WebGrease.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\7a6f1e22\0016534c_1a87d401\System.Web.Razor.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\0bd5514f\8682d14f_c649d701\LgbtqWebsiteNoDb.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\5eada7ec\003c87e2_1a87d401\System.Web.WebPages.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\bfe09c51\003c87e2_1a87d401\System.Web.Helpers.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Web.PageInspector.Loader\v4.0_1.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Web.PageInspector.Loader.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\0103d10e\00c8d184_3aaece01\Antlr3.Runtime.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\39611dac\001cbe16_536acd01\Microsoft.Web.Infrastructure.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\129223b9\003c87e2_1a87d401\System.Web.WebPages.Deployment.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\b4261359\00cdd33c_1a87d401\System.Web.Mvc.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\assembly\dl3\dd04c433\00eff220_9da8d301\Newtonsoft.Json.dll" /out:"C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\App_Web_index.cshtml.f024d85f.citsmrxd.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701;612;618 /warnaserror- "C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\App_Web_index.cshtml.f024d85f.citsmrxd.0.cs" "C:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\App_Web_index.cshtml.f024d85f.citsmrxd.1.cs"
Microsoft (R) Visual C# Compiler version 4.8.4084.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240
c:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\App_Web_index.cshtml.f024d85f.citsmrxd.0.cs(31,106): error CS1003: Syntax error, '>' expected
c:\Users\marfx\AppData\Local\Temp\Temporary ASP.NET Files\root\ec7221e8\6a6fd7fe\App_Web_index.cshtml.f024d85f.citsmrxd.0.cs(31,106): error CS1519: Invalid token ';' in class, struct, or interface member declaration
I have tried to redirect the users to other pages via Razor with Response.Redirect("/Tools");
我试图通过 Razor 和
Response.Redirect("/Tools");
but this doesn't work either, throwing a different exception on the same line (compiler just picked a different character to throw on).但这也不起作用,在同一行抛出不同的异常(编译器只是选择了一个不同的字符来抛出)。
My Tools controller我的工具 controller
using System.Collections.Generic;
using System.Web.Mvc;
using LgbtqWebsiteNoDb.Models;
using static LgbtqWebsiteNoDb.Models.Tool;
using Microsoft.Ajax.Utilities;
namespace LgbtqWebsiteNoDb.Controllers
{
public class ToolsController : Controller
{
private static readonly List<Tool> Tools = new List<Tool>()
{
new Tool
{
ToolName = "Hateful Countries Finder",
ReleaseDate = DateTime.Now.Date,
UpdateDate = DateTime.Now.Date, //GetLastUpdate(toolId:1), //TODO: Fix this method, it looks for the file in the wrong place
ToolId = 1,
ToolDesc = "A tool to find out which countries in the world have anti-Lgbtq+ laws which apply to you",
ToolThumbUrl = "",
ToolThumbAlt = ""
},
new Tool
{
ToolName = "Hateful Map",
ReleaseDate = DateTime.Now.Date,
UpdateDate = DateTime.Now.Date, //GetLastUpdate(toolId:2),
ToolId = 2,
ToolDesc = "A tool to show how many world countries have generic anti-Lgbtq laws",
ToolThumbUrl = "",
ToolThumbAlt = ""
}
};
public static int ToolCount = Tools.Count;
// GET: Tools/
public ActionResult Index()
{
ViewBag.Title = "Tools | Home";
return View();
}
// GET: Tools/HatefulCountriesFinder
public ActionResult HatefulCountriesFinder()
{
ViewBag.Title = "Tools | Hateful Countries";
return View();
}
// GET: Tools/HatefulMap
public ActionResult HatefulMap()
{
ViewBag.Title = "Tools | Hateful Map";
return View();
}
}
}
Tools model工具 model
public class Tool
{
/// <summary>
/// Getter and Setter for the name of a given tool
/// </summary>
public string ToolName { get; set; }
/// <summary>
/// Getter and Setter for the date the tool was released
/// </summary>
[DataType(DataType.Date)] public DateTime ReleaseDate { get; set; }
/// <summary>
/// Getter and Setter for the date the tool was last updated
/// </summary>
[DataType(DataType.Date)] public DateTime UpdateDate { get; set; }
/// <summary>
/// Getter and Setter for the tool ID
/// </summary>
public int ToolId { get; set; }
/// <summary>
/// Getter and Setter for the description of the tool
/// </summary>
public string ToolDesc { get; set; }
/// <summary>
/// Getter and Setter for the thumbnail of the tool image
/// </summary>
public string ToolThumbUrl { get; set; }
/// <summary>
/// Getter and Setter for the alt text of the thumbnail
/// </summary>
public string ToolThumbAlt { get; set; }
/// <summary>
/// Getter and Setter for the number of tools; used for enumeration
/// </summary>
public int ToolCount { get; set; }
/// <summary>
/// A method to update the tool, and change the last updated date
/// </summary>
/// <returns>DateTime</returns>
public static DateTime UpdateTool()
{
//TODO: Write the actual code for this
//TODO: Write new update DateTime to the appropriate file; See GetLastUpdate() for more
return DateTime.Now.Date;
}
}
}
Tools/Index.cshtml工具/索引.cshtml
@model LgbtqWebsiteNoDb.Models.Tool;
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>@ViewBag.Title</title>
<!-- Removed the bulk of the head -->
</head>
<body>
<div class="title">
</div>
<table>
@for (var i = 0; i < @Model.ToolCount; i++)
{
<tr>
<td>
<div class="toolTitle">
@Model.ToolName;
</div>
<div class="toolThumb">
<img src=@Model.ToolThumbUrl alt=@Model.ToolThumbAlt>
</div>
<div class="toolDesc">
@Model.ToolDesc;
</div>
</td>
</tr>
}
</table>
</body>
</html>
I am using.Net v4.7.2 (I would be using 5.0.0 but none of my IDEs seem to want to use the newest version, I'm on a time crunch so can't spend ages debugging that so I'm just making do)我正在使用.Net v4.7.2(我将使用 5.0.0,但我的 IDE 似乎都不想使用最新版本,我时间紧迫,所以不能花很多时间调试,所以我只是凑合)
Cheers干杯
to me you missed Syntax error, '>' expected for img tag in file Tools/Index.cshtml对我来说,您错过了语法错误,文件 Tools/Index.cshtml 中的 img 标记应为“>”
I'm not entirely sure but the ;
我不完全确定,但
;
at the end of the line:在行尾:
@model LgbtqWebsiteNoDb.Models.Tool;
in Tools/Index.cshtml
might be messing it up在
Tools/Index.cshtml
中可能会搞砸
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.