diff --git a/src/DotVVM.Framework.Tests.Owin/DefaultViewModelSerializerTests.cs b/src/DotVVM.Framework.Tests.Owin/DefaultViewModelSerializerTests.cs
index 25302f0702..f1ccb696c2 100644
--- a/src/DotVVM.Framework.Tests.Owin/DefaultViewModelSerializerTests.cs
+++ b/src/DotVVM.Framework.Tests.Owin/DefaultViewModelSerializerTests.cs
@@ -111,7 +111,9 @@ public void Serializer_Valid_ExistingValueNotReplaced()
Assert.AreEqual(123, viewModel.Property.GetPrivateField());
}
- private string SerializeViewModel(object viewModel)
+
+
+ private string SerializeViewModel(object viewModel)
{
context.ViewModel = viewModel;
serializer.SendDiff = false;
@@ -320,11 +322,28 @@ public void DefaultViewModelSerializer_EnumInCollection()
Assert.AreEqual(oldViewModel.Children[2].Property1, newViewModel.Children[2].Property1);
}
+ [TestMethod]
+ public void Serializer_Valid_BindBothOnGetOnlyProperty()
+ {
+ var json = SerializeViewModel(new GetOnlyPropertyViewModel { Property = 42 });
- ///
- /// Wraps the serialized view model to an object that comes from the client.
- ///
- private static string WrapSerializedViewModel(string result)
+ var viewModel = new GetOnlyPropertyViewModel();
+ PopulateViewModel(viewModel, json);
+ Assert.AreEqual(43, viewModel.PropertyPlusOne);
+ }
+
+ public class GetOnlyPropertyViewModel
+ {
+ public int Property { get; set; }
+ [Bind(Direction.Both)]
+ public int PropertyPlusOne => Property + 1;
+ }
+
+
+ ///
+ /// Wraps the serialized view model to an object that comes from the client.
+ ///
+ private static string WrapSerializedViewModel(string result)
{
return string.Format("{{'currentPath':[],'command':'','controlUniqueId':'','viewModel':{0},'validationTargetPath':'','updatedControls':{{}}}}".Replace("'", "\""), result);
}
diff --git a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs
index 8bcf98b63d..3c2bd40cb8 100644
--- a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs
+++ b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs
@@ -94,7 +94,7 @@ public Action CreateRead
block.Add(Expression.Assign(value, Expression.Convert(valueParam, Type)));
// go through all properties that should be read
- foreach (var property in Properties.Where(p => p.TransferToServer))
+ foreach (var property in Properties.Where(p => p.TransferToServer && p.PropertyInfo.SetMethod != null))
{
if (property.ViewModelProtection == ProtectMode.EncryptData || property.ViewModelProtection == ProtectMode.SignData)
{
@@ -235,7 +235,7 @@ public Action C
{
var endPropertyLabel = Expression.Label("end_property_" + property.Name);
var options = new Dictionary();
- if (property.TransferToClient)
+ if (property.TransferToClient && property.PropertyInfo.GetMethod != null)
{
if (property.TransferFirstRequest != property.TransferAfterPostback)
{