문제

나는 이제 막 asp.net mvc를 사용하기 시작했습니다.잘 몰라서 actionlink html helper에 대해 질문하고 싶습니다..

내 index.aspx 홈 뷰에 이 코드가 있습니다.

    <%  Dim _news As datatable = ViewData.Model%>
    <%  For count As Integer = 0 To _news.Rows.Count - 1%>
    <%  Dim id As Integer = _news.Rows(count).Item("IDnews")%>
    <%=_news.Rows(count).Item("newsTitle")%>
    <p>
    <%=_news.Rows(count).Item("newsContent")%><br />
    <%=Html.ActionLink("Read More..", "NewsPublic", "Administration", New With {id})%>
    </p>
    <%Next%>

작업 링크를 클릭하면 다음 URL로 렌더링될 것으로 예상했습니다./관리/신문/7이지만 오히려이 URL을 제공합니다./홈/뉴스공개?길이=14

actionlink는 동일한 컨트롤러에서만 ID를 전달합니까?

미리 감사드립니다!

도움이 되었습니까?

해결책

기본적으로 Html.ActionLink는 현재 컨트롤러를 사용합니다.그러나 ActionLink()에는 약 12개의 오버로드가 있으며 컨트롤러 매개변수를 허용하는 여러 버전이 있습니다.노력하다:

Html.ActionLink("Read More...", 
                 "NewsPublic", 
                 "Administration",
                 New With { .id = id },
                 null)

다른 팁

링크를 렌더링합니다 /관리/신문/7 당신은 사용해야합니다

<%=Html.ActionLink("Read More..", "NewsPublic", "Administration", 
    New With {.id = 7}, Nothing)%>

다섯 번째 매개 변수는 컴파일러를 선택할 수 있습니다

ActionLink(string linkText, string actionName, string controllerName, 
    object routeValues, object htmlAttributes)

확장 메소드 오버로드 대신

ActionLink(string linkText, string actionName, object routeValues, 
    object htmlAttributes)

매개 변수 할당을 추가하는 것을 잊지 마십시오

New With {.id = 7}

대신에

New With {.id}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top