【发布时间】:2010-11-25 22:56:07
【问题描述】:
我正在通过构建一个小型示例网站来试用 ASP.Net MVC2,该网站除其他功能外,还为用户提供了“联系我们”页面。这个想法是允许用户输入他们的姓名、电子邮件地址、消息主题和消息。要发送消息,用户单击 ActionLink。这是视图:
<% Html.BeginForm(); %>
<div>
<%: Html.Label("Name")%>
<br />
<%: Html.TextBox("txtName", "",new { style = "width:100%" })%>
<br />
<%: Html.Label("Email address")%>
<br />
<%: Html.TextBox("txtEmail", "", new { style = "width:100%" })%>
<br />
<%: Html.Label("Subject")%>
<br />
<%: Html.TextBox("txtSubject", "", new { style = "width:100%" })%>
<br />
<%: Html.Label("Message")%>
<br />
<%: Html.TextBox("txtMessage", "", new { style = "width:100%" })%>
</div>
<div style='text-align: right;'>
<%:
Html.ActionLink("Send", "SentEmail", new { name = Html.g, sender = "txtEmail", subject = "txtSubject", message="txtMessage" })
%>
</div>
<% Html.EndForm(); %>
这个想法是,一旦单击 ActionLink,就会调用控制器中的一个方法,用户名、电子邮件地址、主题和消息将被传递到该方法中。这是控制器中的方法:
public ActionResult SentEmail(string name, string sender, string subject, string message)
{
//Send email here and then display message contents to user.
ViewData["Name"] = name;
ViewData["Message"] = message;
ViewData["ThankyouMessage"] = "Thank you for contacting us. We will be in touch as soon as possible.";
return View();
}
但是...当我单击链接时,传递给该方法的值为空。我曾尝试创建一条路线来执行此操作,但它也不起作用。我应该使用其他方法吗?
谢谢,
莫里斯
【问题讨论】:
标签: asp.net-mvc-2 parameter-passing actionlink