使用Ajax.ActionLink发布表单字段

use*_*993 4 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.')" })

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

Dar*_*rov 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" />   
}
Run Code Online (Sandbox Code Playgroud)