Hi I Have a situation like this.
I have to populate 2 labels and 1 drop-down list in the UI with a call to a Web-method.
As the function is static , I am unable to access the page elements (labels and drop-down list ) from within the web-method. So I am trying to return the HTML that I want.
[WebMethod()]
public static object[] GetStatus()
{
//Return text for Label1;
//Return text for Label2;
//Return items to display in ListBox [Number of items can vary]
}
I think object[] may work ..But is it the best way to handle this situation ? Also considering the java script code needed to set the value for these controls (after calling the web-method) what is the best practice in such scenarios ?
create a ViewModel class.
public class StatusViewModel
{
public string Label1 { get; set; }
public string Label2 { get; set; }
public IDictionary<string, string> ListBox { get; set; }
}
[WebMethod()]
public static StatusViewModel GetStatus()
{
// do work
return new StatusViewMode....
}
How about string[]
? Have you tried that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With