我的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是空的。那么我该怎么做呢?
谢谢。
发布于 2011-04-19 22:24:38
我想我看到了问题所在。尝试重新定义模型,这样它就不会定义ActionLink = Model.Username,而只是让MVC的自动绑定负责将字段值发送给您的操作方法。
当从视图生成html时,将计算ActionLink方法调用的值,因此此时您的模型将只包含您在返回视图的前一个操作方法中放入的内容。您需要的是在页面显示并触发http post之后用户在字段中输入的值,它负责MVC绑定管道。
https://stackoverflow.com/questions/5712691
复制相似问题