Is it possible to only accept post back values from a nested view model?
For example, I would like to post only the 'Address':
@Html.TextBoxFor(p => p.User.Account.Address.Street)
@Html.ValidationMessageFor(p => p.User.Account.Address.Street)
To this controller action:
Currently the values only post back if I pass the Address to it's own partial view so that the properties look like:[HttpPost]
public ActionResult SaveAddress(Address address) {
// save to db here
}
@Html.TextBoxFor(p => p.Street)
@Html.ValidationMessageFor(p => p.Street)
You could specify the binding prefix:
[HttpPost]
public ActionResult SaveAddress([Bind(Prefix = "User.Account")] Address model)
{
...
}
Another possibility is to use a partial:
@Html.Partial("_Address", Model.User.Account.Address)
and inside _Address.cshtml
:
@model Address
@Html.TextBoxFor(p => p.Street)
@Html.ValidationMessageFor(p => p.Street)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With