2011-04-19 118 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绑定管道。