2011-04-19 37 views
0

我的MVC應用程序出現問題。 我有一個登錄視圖MVC ActionLink問題

<% Html.EnableClientValidation(); %> 

<% using (Html.BeginForm()) 
    {%> 
    <%: Html.ValidationSummary(true)%> 

    <fieldset> 
     <legend>Login</legend> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.Username)%> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBoxFor(model => model.Username)%> 
      <%: Html.ValidationMessageFor(model => model.Username)%> 
     </div> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.Password)%> 
     </div> 
     <div class="editor-field"> 
      <%: Html.PasswordFor(model => model.Password)%> 
      <%: Html.ValidationMessageFor(model => model.Password)%> 
     </div> 

     <p> 
      <input type="submit" value="Login" /> 
     </p> 



    </fieldset> 
     <%: Html.ActionLink("Set Email", 
       "SetEmail", 
       "GASLogin", 
          new {model = Model.Username}, 
       null)%> 
<% } %> 

和一個ActionLink。當我單擊動作鏈接時,我會發送一封電子郵件到文本框「<%:Html.TextBoxFor(model => model.Username)%>」的郵件地址。 問題是我的Model.Username爲空。 那麼我該如何做到這一點?

謝謝。

回答

0

我想我看到了問題。嘗試重新定義ActionLink,以便它不定義model = Model.Username,並讓MVC的自動綁定負責將字段值發送到您的操作方法。

當從視圖生成html時,ActionLink方法調用會被評估,因此在那時您的模型將只包含您從前一個返回視圖的操作方法中放入的內容。你想要的是用戶在顯示頁面和觸發http帖子之後在域中輸入的值,這是爲了處理MVC綁定管道。