Asp.net Mvc1
在我的Views/home/Index.aspx
上哪些路线从 http://localhost/DefectSeverityAssessmentMvcBeta/
这会渲染
Response.Write("<a href=\"");
Response.Write(Url.Action("Create", "Registration"));
Response.Write("\">Begin Registration</a>");
但对于链接地址http://localhost/DefectSeverityAssessmentMvcBeta/Registration/Create
返回404
虽然这不会在 View 源中渲染或显示,但不会导致任何异常:
Html.ActionLink("Begin Registration", "Create", "Registration");
我有一个 RegistrationController 和一个 /Views/Registration/Create.aspx
注册 Controller 在 Index() 和 Create() 上有断点,但它们没有被命中。
我不知道如何使用<%= %>
在这种情况下,因为它位于以下代码块内:
<% if (ViewData.ContainsKey("user"))
{
if (ViewData.ContainsKey("registered") && (bool)ViewData["registered"] == true)
{
//Html.RouteLink("Resume Assessment", "Assessment", new { controller = "Assessment", action = "Index" });
Response.Write("<a href=\"");
// Html.ActionLink("Resume Assessment", "Index", "Assessment");
Response.Write("\">Resume Assessment</a>");
}
else
{
//Html.RouteLink("Begin", "Registration", new { controller = "Registration", action = "Edit" });
// Html.ActionLink("Begin Registration", "Create", "Registration");
Html.RouteLink("Begin", "Default", new { controller = "Registration", action = "Edit" });
//Response.Write("<a href=\"");
//Response.Write(Url.Action("Create", "Registration"));
//Response.Write("\">Begin Registration</a>");
}
}
else
{ Response.Write("Authentication failed"); }
%>
最佳答案
您是否在 HTML 中为 Response.Write 和 Html.ActionLink 使用 <% %>?尝试使用 <%= %> 表示 Html.ActionLink(...);
添加的等号在幕后调用 Response.Write,从而将代码写入屏幕。
关于asp.net-mvc - 为什么 Response.Write 会渲染而 Html.ActionLink 不会?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1798281/