0

I am new to MVC and I want to get the data out of my model in view, my code is given below and the corresponding class as well.when I tried to do using the existing code it gives me error,The model item passed into the dictionary is of type .. but this dictionary requires a model item of type

        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()
    {

    }
}
tereško
  • 58,060
  • 25
  • 98
  • 150
Russian Federation
  • 194
  • 1
  • 5
  • 24
  • Can you debug and inform in what line are you getting this error? There is a possibility that the code in the view is causing this error. Can you post the view code or at least the main parts, like the Model that the view is expecting and parts of the view that is using this Model? Regards. – dime2lo Aug 02 '18 at 17:39
  • I just want to display firstname, lastname and email on view that's all – Russian Federation Aug 02 '18 at 17:50
  • Paste in your view – HighlanderGrogg Aug 02 '18 at 19:00

0 Answers0