使用Ajax.ActionLink发布表单字段

时间:2012-01-29 00:46:03

标签: asp.net-mvc-3

我的MVC 3应用程序中有一个View,允许用户输入送货地址并下订单。我在视图上显示的表单字段与用户配置文件字段完全相同。所以我想考虑一个链接,供用户将他们输入的数据保存到他们的个人资料中。名字,姓氏,地址等字段。 我想使用Ajax.ActionLink,但问题是我不知道如何将表单字段发送到保存数据的Action。我所拥有的是:

@Ajax.ActionLink("Save into profile", "SaveAccountProfile", new{ address=????}, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, OnSuccess = "alert('Account profile was successfully updated.')" })

我会发布什么作为路线数据?

1 个答案:

答案 0 :(得分:7)

在这种情况下,您应该使用Ajax.BeginForm。这样,表单字段值将自动发布到服务器。

@using (Ajax.BeginForm("SaveAccountProfile", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, OnSuccess = "alert('Account profile was successfully updated.')" }))
{
    ... some input fields
    <input type="submit" value="Save into profile" />   
}
相关问题