我是MVC的新手,我想从模型中获取数据,下面给出了我的代码以及相应的类。当我尝试使用现有代码进行操作时,它给了我错误,传递到字典中的模型项的类型为..,但此字典需要模型项的类型
public ActionResult Index(string userid)
{
var model = new AssociationsViewModel()
{
userid = userid,
str = getAssociations(userid)
};
//AssociationsViewModel.RootObject obj = new AssociationsViewModel.RootObject();
// List< AssociationsViewModel.RootObject> obj2 = model.userlist;
//AssociationsViewModel flight = Newtonsoft.Json.JsonConvert.DeserializeObject<AssociationsViewModel>(model);
return View(model);
}
public JsonResult getAssociations(string id)
{
var inputData = new Dictionary<string, string>()
{
{ "databaseName", string.IsNullOrEmpty( Helper.databasename)? "" : Helper.databasename},
{ "sourceUrl", Helper.sourceurl},
{ "physicianId", id },
};
var str = _client.FetchData
(
"associations/getAssociations",
inputData
);
return Json( str.Content.ToString());
}
public class AssociationsViewModel
{
public string userid { get; set; }
public System.Web.Mvc.JsonResult str { get; set; }
public class RootObject
{
public string firstname { get; set; }
public string lastname { get; set; }
public string email { get; set; }
}
public List<RootObject> userlist { get; set; }
public AssociationsViewModel()
{
}
}