Clink50
❔ Need help understanding Model Binding better
Hmm maybe I'm asking the wrong way.
The title and description and other values don't need to be in any form, they are just to display some values on the page. The values that do matter are the RedirectOption and the HoursRead. But the viewmodel requires those two properties + the 15 other static properties when I submit the form in order for all the whole thing to be bound in case of an error an I have to return the whole view back to the page. I guess I just don't understand how it's supposed to work in this case.
I'm used to just sending an api request with the values that I need and then if there was an error, just showing those error messages through JS.
Every example I've looked at so far is just showing a whole page as a form, but that's not realistic. I could have a page with static content that comes from the CMS displays at the top, and then a call to action form at the bottom of the page. But using MVC, I would have to have all the static content bound to the viewmodel plus the form properties in order for me to be sent back to the same page and no values changed on the form if there was an error.
Hopefully I'm making sense.
18 replies
❔ Need help understanding Model Binding better
Here is another example. Is there not a better way to do this? I shouldn't have to put all 20 values in the form as hidden elements when all I need is the redirectoption and hoursread in the form request.
18 replies
❔ Need help understanding Model Binding better
Taking the below as an example, let's say I take the StudentPage as a viewmodel instead of just a Student model. The StudentPage model has a title, description, books, and 15 more properties just as an example. When I submit the form, I have to pass all 15+ properties with the form request, when all I actually needed was the name and the age in the request. Is this expected? It seems wrong.
18 replies