✅ How can I pass data from JS to a ViewModel?
Sorry in advance if the issue is JS related.
I'm trying to make a small MVC project - I'm having trouble trying pass an object from JS then to the Controller. I can pass the data normally when using a Model but I don't know how to do it when dealing with a ViewModel.
The Transactions Model would always return a NULL.
Any help is very much appreciated. Many Thanks!
JS Function:
Controller:
ViewModel:
5 Replies
Well, the shape of the data doesn't match
You're sending
but the
TransactionsVM
your endpoint expects is
And you seem to be just discarding the two list properties...?Thanks for the answer.
I'm only using the lists to display contents for a select input, they're on ValidateNever, because I'm trying to have all CRUD operations on one page. But I'm not sure if its a smart idea.
Since im trying to return only the Transactions, it should look something like this right?
Create a DTO just for data input, something like
make your controller take a
TransactionData data
, and send a JSON like
You don't have to — and shouldn't, really — use the same class for data input and data outputGot it working now, thanks so much.
Its a small personal project but I'll try to clean up my code as a learning experience.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.