I am trying to update CRM 2016 via an ASP.Net MVC 4 portal using late binding. I have an Option Set field that i am trying to update using the OptionSetValue(Convert.ToInt32()) but the field does not update. Below are code snippets of my model and controller.
ViewModel:
public class NominatorOrganizationViewModel
{
[Display(Name = "Are you submitting this nomination on behalf of an organization?")]
public YesOrNoSelectionOrganization OnBehalfOfOrganizationYesOrNo { get; set; }
[Display(Name = "If yes, Nominating Organization:")]
public string txtOrganization { get; set; }
[DataType(DataType.MultilineText)]
[Display(Name = "If yes, describe your position in the organization:")]
public string txtOrganizationPosition { get; set; }
}
Enum values for Yes/No
public enum YesOrNoSelectionOrganization
{
Nothing = 0,
Yes = 1,
No = 2
}
Controller
This code will not work to set the CRM field value
oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(Convert.ToInt32(NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo));
To work around setting the field, I can use the below code but I don’t think it’s good coding practice and there should be a perfectly good explanation as to why the above code it’s working, I just can’t figure it out. The code above is similar to other option sets being set throughout the portal but the 1 particular piece of code mentioned above isn’t updating (no errors, just not updating).
if (NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo == YesOrNoSelectionOrganization.Yes)
{
oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(2);
}
else if (NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo == YesOrNoSelectionOrganization.No)
{
oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(1);
}
else
{
oasys_nomination["oasys_memberofnominatingorganization"] = null;
}
Any ideas?
*This post is locked for comments