public ActionResult UpdateValue(ChangedDataItems[] changedValues) { /* some delay */ System.Threading.Thread.Sleep(1000); String status = null; foreach (ChangedDataItems dataItem in changedValues) { MyItem item = GetList.First(i => i.Id == dataItem.key); /* some way to set a propery */ PropertyInfo info = item.GetType().GetProperty(dataItem.field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty); if (info.CanWrite) { info.SetValue(item, TypeDescriptor.GetConverter(info.PropertyType).ConvertFromString(dataItem.value), null); } else { status = "Updating cannot be performed over a readonly field"; break; } } if (status == null) { status = "All fields successfully updated"; } return(Content(status)); }
public ActionResult UpdateValue(Int32 key, String field, String value) { /* some delay */ System.Threading.Thread.Sleep(1000); MyItem item = GetList.First(i => i.Id == key); /* some way to set a propery */ PropertyInfo info = item.GetType().GetProperty(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty); String status; if (info.CanWrite) { info.SetValue(item, TypeDescriptor.GetConverter(info.PropertyType).ConvertFromString(value), null); status = String.Format("Field: <b>{0}</b> is updated with the <i>{1}</i> value", field, value); } else { status = "Updating cannot be performed over a readonly field"; } return(Content(status)); }