为什么这个cshtml会给出运行时错误

时间:2011-09-09 11:09:17

标签: asp.net-mvc asp.net-mvc-3

有人能告诉我为什么这段代码会给出运行时错误:

  @if (Request.IsAuthenticated) {


        Welcome <b>Page.User.Identity.Name;</b>!
        [ Html.ActionLink("Log Off", "LogOff", "Account"); ]
       <br />     
        <br />     
        [ Html.ActionLink("Change Password", "ChangePassword", "Account"); ]
         <br />  
    }
    else { 
        [Html.ActionLink("Candidate Login", "LogOn", "Account",new { id = 1 },null);]
    <br />     
    <br />     
        [Html.ActionLink("Employer Login", "LogOn", "Account", new { id = 2 }, null);]
    <br />     

}

我该怎么做才能避免它?我在这些大括号后面变得疯狂,html混淆了

1 个答案:

答案 0 :(得分:1)

我会试一试:

@if (Request.IsAuthenticated) {
  Welcome <b>@Page.User.Identity.Name</b>!
  @Html.ActionLink("Log Off", "LogOff", "Account")
  <br />     
  <br />     
  @Html.ActionLink("Change Password", "ChangePassword", "Account")
   <br />  
 }
 else
 { 
   @Html.ActionLink("Candidate Login", "LogOn", "Account",new { id = 1 },null)
   <br />     
   <br />     
   @Html.ActionLink("Employer Login", "LogOn", "Account", new { id = 2 }, null)
   <br />     
 }