Sam Khan Sam Khan - 4 days ago 9
C# Question

Call a method property in view from a class?

From the class

PCSS.Common.Configuration.ConfigurationFunctions
I need to call the method property
var qe = new QueryExpression("pcs_configurationitem");
in my view.

var qe = new QueryExpression("pcs_configurationitem"); is in a string method

below is the code of var qe in a string, and I need to call pcs_configurationitem in view.

public static string GetString(string key, IOrganizationService service)
{
var qe = new QueryExpression("pcs_configurationitem"); //want this in view
qe.Criteria.AddCondition(new ConditionExpression("pcs_name", ConditionOperator.Equal, key));
qe.Criteria.AddCondition(new ConditionExpression("pcs_valuetype", ConditionOperator.Equal, (int)ConfigItemType.String));
qe.Criteria.AddCondition(new ConditionExpression("pcs_stringvalue", ConditionOperator.NotNull));
qe.ColumnSet = new ColumnSet(new string[] { "pcs_stringvalue" });
var results = service.RetrieveMultiple(qe);
if (results.Entities.Count == 0) throw new Exception("No value of this type found for key " + key);
return (results[0].GetAttributeValue<string>("pcs_stringvalue"));
}


Im trying to do something like below to call it in my view.

<span title="Feedback is not suppored more than @ConfigurationFunctions.("pcs_configurationitem") days after closing the enquiry.">`</span>`


However this is not working, please advise.

Answer

You can put some code at the top of your page:

@model MyModel
@{
  var qe = new QueryExpression("pcs_configurationitem"); 
}

Then down in your markup:

<span title="Feedback is not suppored more than @qe days after closing the enquiry."></span>

You may need to add a @using directive at the top to reference the appropriate namespace for QueryExpression.

Comments