2009-11-25 5 views
2

Asp.net MVC1 http://localhost/DefectSeverityAssessmentMvcBeta/Response.Write는 렌더링하지만 Html.ActionLink는 왜 렌더링되지 않습니까?

에서 내 Views/home/Index.aspx하는 경로에 이

Response.Write("<a href=\""); 
    Response.Write(Url.Action("Create", "Registration")); 
    Response.Write("\">Begin Registration</a>"); 

를 렌더링하지만 렌더링 또는 표시되지 않지만 링크 http://localhost/DefectSeverityAssessmentMvcBeta/Registration/Create

의 주소 404을 반환 소스는 볼 수 있지만 예외는 없습니다.

나는 RegistrationController와 a를 가지고있다 /Views/Registration/Create.aspx 등록 컨트롤러에는 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"); } 
      %> 
+0

흥미로운 점은 첫 번째 방법은 404가 반환되는 링크를 생성한다는 것입니다. 경로가 존재하는지 궁금합니다. –

+0

이 기본 경로로 들어가면 안됩니까? 그것은/controller/action 형식입니다. – Maslow

답변

4

Response.Write와 Html.ActionLink 모두에서 HTML에 < %%>를 사용하고 있습니까? Html.ActionLink (...)에 대해 < % = %>을 사용해보십시오.

추가 된 등호는 Response.Write를 호출하여 화면에 코드를 작성합니다.

+0

= 기호는 표현식을 의미한다고 생각했습니다. If 문과 코드 블록을 오른쪽에서 사용할 수 없습니까? – Maslow

+0

+1이 답변은 도움이됩니다. 뒷 배경의 Response.write에 대해 알지 못했습니다. – Maslow

+1

if 문을 <% %>에 랩핑하고 실제로 출력 된 내용을 <%= %> –

0

당신이이 컨텍스트 스위치에 등호를 사용하고 다음과 같이 :

나는 다음과 같은 코드 블록 내부이기 때문에이 시나리오에서 <%= %>을 사용하는 방법을 모르겠어요?

<%= Html.ActionLink("Begin Registration", "Create", "Registration"); %> 
    ^--needs equals sign here 

등호를 사용하지 않는 경우 응답 개체에 직접 작성해야합니다.

라우팅 오류가 발생하는 한 Phil Haack의 진단 도구 http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx을 사용하여 경로를 확인할 수 있습니다.

라우팅에 IIS7 requires special configuration보다 작은 값이 있습니다.

+0

'= ' – Maslow

+0

을 사용하지 않는 이유를 포함하도록 질문을 업데이트했습니다. 그러면 Response.Write를 사용해야합니다. 404는 라우팅 문제와 비슷합니다. –

+0

라우팅 문제를 어떻게 진단 할 수 있습니까? – Maslow

2

Html.ActionLink는 문자열을 반환하고 응답 스트림에 쓰지 않기 때문에. 당신은 내가 그것을 작업 얻었다 찰스 콘웨이에

<% if(x) {%> <%=Html.ActionLink(...)%><% } %> 

감사를 사용할 수있는 능력을 활용하지 않은 <%= %> 또는 Response.Write();

Response.Write(Html.ActionLink("Begin Registration", "Create", "Registration")); 
0

를 사용하여 페이지를 작성해야합니다. 흥미로운 코드는 다음과 같습니다.

<div class="entry"> 
<% if (ViewData.ContainsKey("user")) 
    { 
     if (ViewData.ContainsKey("registered") && (bool)ViewData["registered"] == true) 
     { %> 
      <%=Html.ActionLink("Resume Assessment", "Index", "Assessment") %> 

     <% } 
     else 
     { %> <%=Html.ActionLink("Begin Registration", "Create", "Registration") %> 

      <% 
     } 


    } 
    else 
    { Response.Write("Authentication failed"); } 
      %></div> 
관련 문제