Fields for form fields with Ajax.ActionLink

I have a view in my MVC 3 application that allows a user to enter a delivery address and place an order. The form fields that I display on the view are exactly the same as the user profile fields. Therefore, I want to consider the link for the user in order to save the data that they entered into their profile. Fields such as first name, last name, address, etc. I want to use Ajax.ActionLink, but the problem is that I do not know how to send form fields to an action that saves data. I have:

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

What would I publish as route data?

+4
source share
1 answer

In this case, you should use Ajax.BeginForm . Thus, the values โ€‹โ€‹of the form fields will be automatically sent to the server.

 @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" /> } 
+7
source

Source: https://habr.com/ru/post/1393562/


All Articles