Reputation: 1
[BindProperty]
public string Source { get; set; }
[TempData]
public string Destination{ get; set; }
When model binding data to a view item, I am able to capture data from a model when I use the [BindProperty] attribute on a property, and assign it to a property that has the [TempData] attribute. But now, if I want to assign it back, it doesn't work
If I make both of the properties as [Required] and [BindProperty], I cannot capture the data from the source..
Is there a way to do real two way binding so I can copy data back and forth between two properties on each return Page();?
Upvotes: 3
Views: 9017
Reputation: 2983
BindProperty allow us to have a two way binding but you will also need an input. This works like this. You set the value of the BindProperty and you create an input which will host the value of the property.
<input asp-for="Source" class="form-control" />
This will have as a result, when you submit the form, all the values in the input controls will be transferred to the equivalent BindProperty value.
If you do not have input, you will loose the value. This is how it works.
Upvotes: 5