title: How to convert string to nullable int LINQ
body: <p>I saw a lot of questions like this but seems I cant find anything to relate one to another and find solution for mine. I am using MVC 4 application where I have a dropdownlist with some values inside.</p>
  
  <p>I am using viewbag to populate it.</p>
  
  <pre><code>ViewBag.Roles = new SelectList(db.Roles, "RoleId", "RoleName");
  </code></pre>
  
  <p>In the view my dropdown looks like this. </p>
  
  <pre><code>@Html.DropDownList("selectedRole", ViewBag.Roles as SelectList, String.Empty)
  </code></pre>
  
  <p>The string <code>selectedRole</code> is getting the <code>RoleId</code> value from the view.</p>
  
  <p>After this I am doing some LINQ to the database with <code>selectedRole</code> which says that I cannot convert string to Int inside my LINQ which I really want so I can return better results.</p>
  
  <pre><code>     public ActionResult SearchResults(string selectedRole, string selectedCourse, string SearchParam)
          {
              var members = (from m in db.Members
                             select m);
  
              if (!String.IsNullOrEmpty(selectedRole))
              {
                  members = (from m in db.Members
                             where m.UserRole == Int32.Parse(selectedRole)
                             select m);
  
  
              }
          //some more if's here...
          return View(members.ToList());
  }
  </code></pre>
  
  <p>So the question is how to convert this <code>selectedRole</code> to Integer. Are there any rules to follow when converting in LINQ?</p>
  
  <p>PS: I tried also <code>Convert.ToInt32(selectedRole)</code> which returns same error.</p>