MVC ActionLink 问题

发布于 2024-11-02 05:24:01 字数 1395 浏览 3 评论 0原文

我的 MVC 应用程序有问题。 我有一个登录视图

<% 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 为空。 那么我该怎么做呢?

谢谢。

I have a problem with my MVC app.
I have a login view

<% 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)%>
<% } %>

and a ActionLink. When i click the actionlink i whant to send an email to the mail address in the text box "<%: Html.TextBoxFor(model => model.Username)%>" .
The problem is that my Model.Username is null.
So how can i do this?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪淡了忧伤 2024-11-09 05:24:01

我想我看到了问题所在。尝试重新定义 ActionLink,以便它不定义 model = Model.Username,而只是让 MVC 的自动绑定负责将字段值发送到您的操作方法。

当从视图生成 html 时,将对 ActionLink 方法调用进行评估,因此此时您的模型将仅包含您从返回视图的先前操作方法中放入的内容。您想要的是在页面显示并触发 http post 后用户在字段中输入的值,该值由 MVC 绑定管道负责。

I think I see the problem. Try redefining the ActionLink so that it doesn't define model = Model.Username, and just let MVC's automatic binding take care of sending the field values to your action method.

The ActionLink method call gets evaluated when the html is generated from the view, so at that point your model will only contain stuff you've put in it from a previous action method which returns the view. What you want is the value put in the field(s) by the user after the page is displayed and the http post triggered, which is taken care of MVCs binding plumbing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文