title: Get value from property in foreach loop
body: <p>I am having an issue getting the values from a property of a type viewmodel I am passing in.  This is my current method, I believe the name of the property is being stored right, but I can't seem to get the value to work.  Any advice would be greatly appreciated.  I believe I will have problems with the dictionary when the type of value is not always a string also, but that is another problem for later :).</p>
  
  <p>Here is the method taking in the viewmodel type:</p>
  
  <pre><code>public Type ConvertModel(Type mytype) {
              Dictionary&lt;string,string&gt; dic = new Dictionary&lt;string,string&gt;();
  
              foreach (var prop in mytype.GetProperties())
              {
                 dic.Add(prop.Name, prop.GetValue(mytype,null).ToString());
              }
  
              //return mytype;
          }
  </code></pre>
  
  <p>This is how that method is being called(Ignore the method name I am just trying an idea out):</p>
  
  <pre><code>public ActionResult Index()
          {
              var viewmodel = new myViewModel()
              {
                  FirstName = "Shawn",
                  LastName = "Michaels"
              };
  
              var newType = ConvertModel(viewmodel.GetType());
  
              return View();
          }
  </code></pre>
  
  <p>The sample output is that I would eventually pass back another model related to the viewModel (say UserViewModel and UserModel, where UserModel would be filled with the UserViewModel properties and values, except the method should tank in any 2 related models like above.)</p>