How can I fill out a form without using @HTML.Beginform and by using JQuery Ajax instead? Right now I tried:
var postData = { form1: username, form2: pas
This will do a xhr post to the server and return the view as data (response) It will not navigate, if it returns html, you need to set a proper datatype in your request to tell that you expect html back from the server:
Given your action returns html, you can put the returned html on your page in your success function.
postData = "{'ID':'test'}";
$.ajax({
type: "POST",
url: '/Home/Test',
data: postData,
dataType: 'html',
contentType: 'application/json',
traditional: true,
success: function (data) {
$("#yourdomelement").html(data);
}
});
In your action;
public ActionResult Test([FromBody]PostData id)
{
return Content("hello
");
}