Hass
Hass
Explore posts from servers
CC#
Created by Hass on 12/25/2022 in #help
❔ Getting error 500 on form post (using fetch)
I'm trying to do a form post (posting a model), but my controller is not being called. When I check the fetch result on the console, I get a 500 error, but I haven't been able to pinpoint where the problem lies. The model:
public class PostModel
{
public List<string> ImagesPath { get; set; }
public string Description { get; set; }
}
}
public class PostModel
{
public List<string> ImagesPath { get; set; }
public string Description { get; set; }
}
}
The js object I'm posting/ the fetch post:
document.querySelector("#enviaForm").addEventListener("click", function(e) {
const postsToSend = createPostObjectToSend()
// postsToSend is an array composed of objects that looks like this:
// {
// Description: post.querySelector("input[type=text]").value.trim(),
// ImagesPath: []
// }

fetch('/Home/ProcessPosts', {
method: 'POST',
body: postsToSend
})
.then(response => response)
.then(data => {console.log(data)})
})
document.querySelector("#enviaForm").addEventListener("click", function(e) {
const postsToSend = createPostObjectToSend()
// postsToSend is an array composed of objects that looks like this:
// {
// Description: post.querySelector("input[type=text]").value.trim(),
// ImagesPath: []
// }

fetch('/Home/ProcessPosts', {
method: 'POST',
body: postsToSend
})
.then(response => response)
.then(data => {console.log(data)})
})
The ImagesPath is an array of strings, where I get the values from inputs of the type 'file'. The controller
[HttpPost]
public void ProcessPosts(List<PostModel> post)
{

}
[HttpPost]
public void ProcessPosts(List<PostModel> post)
{

}
Maybe I'm missing some basic concept or basic knowledge? I've been trying to fix this for hours but I haven't been able to
38 replies
CC#
Created by Hass on 11/7/2022 in #help
FormCollection converting value from input='text'
1 replies