我试图从我的 Controller 调用我的模型,但出现错误。错误是在
new UserModels(id, searchcriteria);
并指出
UserModels 不包含采用 2 个参数的构造函数。
有什么想法吗?
Controller / Action :
public ActionResult ID(string id)
{
ViewBag.Message = "Customer Information";
string searchcriteria = "userid";
UserModels model = new UserModels(id, searchcriteria);
return View();
}
型号:
public class UserModels
{
public UserData user { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string searchvalue {get; set; }
public string searchcriteria { get; set; }
public List<UserData> UserModel(string id, string searchcriteria)
{
SSO_Methods sso = new SSO_Methods();
List<UserData> userObject = sso.GetUserObject(id, searchcriteria);
return userObject;
}
}
最佳答案
C# 中的构造函数不能返回任何内容。
你的代码需要是
public UserModels(string id, string searchcriteria)
{
// your code here
}
然后如果你想返回一个列表,添加
public List<UserData> GetUserModels(string id, string searchcriteria)
{
SSO_Methods sso = new SSO_Methods();
List<UserData> userObject = sso.GetUserObject(id, searchcriteria);
return userObject;
}
关于c# - 如何从 Controller 调用我的模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18390223/