2012-04-14 5 views
1

특정 페이지에서 하이라이트를 표시하도록 내비게이터를 만들려고합니다. 나는 다음과 같은 것을 가지고있다 :MVC3 면도기 수프 - 템플릿?

<li> 
    @if (Request.Url.AbsoluteUri.ToLowerInvariant().Contains("registration")) 
    { 
     @Html.ActionLink("Request an Invite", "index", "registration", null, new { @class = "active" }) 
    } 
    else 
    { 
     @Html.ActionLink("Request an Invite", "index", "registration") 
    } 
</li> 
<li> 
    @if (Request.Url.AbsoluteUri.ToLowerInvariant().Contains("login")) 
    { 
     @Html.ActionLink("Login", "index", "login", null, new { @class = "active" }) 
    } 
    else 
    { 
     @Html.ActionLink("Login", "index", "login") 
    } 
</li> 

확실한이 방법으로 더 적은 스프를 만들 수 있을까? 누군가 초보자를 도울 수 있습니까?

감사 제임스 우 들리

답변

0

잠재적 유사한 URL을에 오류가 발생하지 않도록 내 생각에 당신은

var contorller = @ViewContext.RouteData.Values["controller"] 
var action = @ViewContext.RouteData.Values["action"] 

다음 코드가 작은 내가 인라인 상태

@Html.ActionLink("Request an Invite", "index", "registration", null, (controller = "Home" && action == "registration") ? new { @class = "active" } : null) 
를 사용할 수 있도록하는 데 사용할 수있는

아이디어를 얻길 바랍니다

+0

정말 고맙습니다. ! –