I know a can save a single property to my db when knowing which propery I need to update, like this (the method SaveContent
triggers trough a AJAX-post from the view):
public void SaveContent(string contentToUpdate)
{
var page = Session.Load<CorePage>("CorePages/1");
page.Title = contentToUpdate;
RavenSession.SaveChanges();
}
But my problem is: the (string contentToUpdate)
-parameter passed into my Save-method could be any property-value from my views @model-class because I use a WYSIWYG-editor om many places in the same view which means I never know which property that is passed in as string contentToUpdate
. So I can't use the type of code a showed in my first exmple.
The string contentToUpdate
could be any of these below:
public class CorePage
{
public string WelcomeHeader { get; set; }
public string WelcomeText { get; set; }
public string LongText { get; set; }
public string ShortDescription { get; set; }
}
So: How can I update a single-Property in var page = Session.Load<CorePage>("CorePages/1");
when the string contentToUpdate
-parameter could be any? And which other parameters do a probably need to pass into the save-method to solve this (the propertyName)?
EDIT:
I don't need to create a new property, I need to find witch property to set the value to.
So by passing in the propertyName as a parameter to my save-method I need to use that value(witch could be any of my properties in my class CorePage
) to update that matching property.
Basiclly, I never know witch of my properties from public class CorePage
is being sent to public void SaveContent
Take a look at this below, and you propably know what I mean:
public void SaveContent(string propertyName, string contentToUpdate)
{
//Philip Kendalls method used here
SaveContent(page => page.propertyName, contentToUpdate);
}