HTTP Exception was unhandled by user code in MVC











up vote
3
down vote

favorite












Was receiving this error:



An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
Additional information: DataBinding: 'Final.Models.Hello' does not contain a property with the name '700'.



I looked through google for some answers, but I still feel lost.



Model class:



public Hello () {

db = new ExtensionDBEntities();
}

public List<Hello> getID()
{
var que = (from rel in db.Table1
select new Hello
{
ID = rel.ID
}).ToList();
return que;
}

public List<Hello> getStuff()
{
var que = (from wre in db.View
select new Hello
{
ID = wre.ID,
Summary = wre.Summary,
Description = wre.Description

}
}


getHello() is the same exact method as the getStuff(), just accepts a string ID parameter.



Controller class:



public ActionResult Index()
{
var model = test.getStuff();
ViewBag.Releases = new SelectList(test.getID(), "", "ID");
ViewBag.Managers = new SelectList(test.getManagers(), "", "Managers");
return View("");
}

[HttpPost]
public ActionResult Selection()
{
string selectedId = Request["IDText"].ToString();
string Managers = Request["ManagersText"].ToString();
var model = test.getStuff();
ViewBag.Releases = new SelectList(test.getID(), selectedId, "ID");
ViewBag.Managers = new SelectList(test.getManagers(), Managers, "Managers");
var que = test.getHello(selectedId, Managers);
return View(que);
}


Index View Class:



 $(document).ready(function () {
$("#Releases").on("change", function () {
var value = $('#Releases :selected').text()
$("#IDText").val(value);
});
$("#Managers").on("change", function () {

var value = $('#Managers :selected').text()
$("#ManagersText").val(value);
});

});
@using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
{
<div class="container" id='div_release'>

@Html.DropDownList("Releases", ViewBag.Releases as SelectList)
@Html.DropDownList("Managers", ViewBag.Managers as SelectList)
@Html.Hidden("IDText", "")
@Html.Hidden("ManagersText", "")
<input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
</div>
}


Selection View Class:



 <div class="container">
<table id="myTable" align="left">
<tr>
<th>@Html.DisplayNameFor(model => model.ID)</th>
<th>@Html.DisplayNameFor(model => model.Summary)</th>
<th>@Html.DisplayNameFor(model => model.Description)</th>
</tr>

@foreach (var item in Model)
{
<tr id="Home">

<td>@Html.DisplayFor(x => item.ID)</td>
<td>@Html.DisplayFor(x => item.Summary)</td>
<td>@Html.DisplayFor(x => item.Description)</td>
</tr>
}

$(document).ready(function () {
$("#Releases").on("change", function () {
var value = $('#Releases :selected').text()
$("#IDText").val(value);
});
$("#Managers").on("change", function () {

var value = $('#Managers :selected').text()
$("#ManagersText").val(value);
});

});
@using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
{
<div class="container" id='div_release'>

@Html.DropDownList("Releases", ViewBag.Releases as SelectList) // Getting the error here....
@Html.DropDownList("Managers", ViewBag.Managers as SelectList)
@Html.Hidden("IDText", "")
@Html.Hidden("ManagersText", "")
<input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
</div>
}
</table>
</div>


The error occurs in the Selection View Class. The View classes are almost identical, the only difference being is the data being displayed in the Selection View Class based on the selected value from the drop down list.










share|improve this question




























    up vote
    3
    down vote

    favorite












    Was receiving this error:



    An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
    Additional information: DataBinding: 'Final.Models.Hello' does not contain a property with the name '700'.



    I looked through google for some answers, but I still feel lost.



    Model class:



    public Hello () {

    db = new ExtensionDBEntities();
    }

    public List<Hello> getID()
    {
    var que = (from rel in db.Table1
    select new Hello
    {
    ID = rel.ID
    }).ToList();
    return que;
    }

    public List<Hello> getStuff()
    {
    var que = (from wre in db.View
    select new Hello
    {
    ID = wre.ID,
    Summary = wre.Summary,
    Description = wre.Description

    }
    }


    getHello() is the same exact method as the getStuff(), just accepts a string ID parameter.



    Controller class:



    public ActionResult Index()
    {
    var model = test.getStuff();
    ViewBag.Releases = new SelectList(test.getID(), "", "ID");
    ViewBag.Managers = new SelectList(test.getManagers(), "", "Managers");
    return View("");
    }

    [HttpPost]
    public ActionResult Selection()
    {
    string selectedId = Request["IDText"].ToString();
    string Managers = Request["ManagersText"].ToString();
    var model = test.getStuff();
    ViewBag.Releases = new SelectList(test.getID(), selectedId, "ID");
    ViewBag.Managers = new SelectList(test.getManagers(), Managers, "Managers");
    var que = test.getHello(selectedId, Managers);
    return View(que);
    }


    Index View Class:



     $(document).ready(function () {
    $("#Releases").on("change", function () {
    var value = $('#Releases :selected').text()
    $("#IDText").val(value);
    });
    $("#Managers").on("change", function () {

    var value = $('#Managers :selected').text()
    $("#ManagersText").val(value);
    });

    });
    @using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
    {
    <div class="container" id='div_release'>

    @Html.DropDownList("Releases", ViewBag.Releases as SelectList)
    @Html.DropDownList("Managers", ViewBag.Managers as SelectList)
    @Html.Hidden("IDText", "")
    @Html.Hidden("ManagersText", "")
    <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
    </div>
    }


    Selection View Class:



     <div class="container">
    <table id="myTable" align="left">
    <tr>
    <th>@Html.DisplayNameFor(model => model.ID)</th>
    <th>@Html.DisplayNameFor(model => model.Summary)</th>
    <th>@Html.DisplayNameFor(model => model.Description)</th>
    </tr>

    @foreach (var item in Model)
    {
    <tr id="Home">

    <td>@Html.DisplayFor(x => item.ID)</td>
    <td>@Html.DisplayFor(x => item.Summary)</td>
    <td>@Html.DisplayFor(x => item.Description)</td>
    </tr>
    }

    $(document).ready(function () {
    $("#Releases").on("change", function () {
    var value = $('#Releases :selected').text()
    $("#IDText").val(value);
    });
    $("#Managers").on("change", function () {

    var value = $('#Managers :selected').text()
    $("#ManagersText").val(value);
    });

    });
    @using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
    {
    <div class="container" id='div_release'>

    @Html.DropDownList("Releases", ViewBag.Releases as SelectList) // Getting the error here....
    @Html.DropDownList("Managers", ViewBag.Managers as SelectList)
    @Html.Hidden("IDText", "")
    @Html.Hidden("ManagersText", "")
    <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
    </div>
    }
    </table>
    </div>


    The error occurs in the Selection View Class. The View classes are almost identical, the only difference being is the data being displayed in the Selection View Class based on the selected value from the drop down list.










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      Was receiving this error:



      An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
      Additional information: DataBinding: 'Final.Models.Hello' does not contain a property with the name '700'.



      I looked through google for some answers, but I still feel lost.



      Model class:



      public Hello () {

      db = new ExtensionDBEntities();
      }

      public List<Hello> getID()
      {
      var que = (from rel in db.Table1
      select new Hello
      {
      ID = rel.ID
      }).ToList();
      return que;
      }

      public List<Hello> getStuff()
      {
      var que = (from wre in db.View
      select new Hello
      {
      ID = wre.ID,
      Summary = wre.Summary,
      Description = wre.Description

      }
      }


      getHello() is the same exact method as the getStuff(), just accepts a string ID parameter.



      Controller class:



      public ActionResult Index()
      {
      var model = test.getStuff();
      ViewBag.Releases = new SelectList(test.getID(), "", "ID");
      ViewBag.Managers = new SelectList(test.getManagers(), "", "Managers");
      return View("");
      }

      [HttpPost]
      public ActionResult Selection()
      {
      string selectedId = Request["IDText"].ToString();
      string Managers = Request["ManagersText"].ToString();
      var model = test.getStuff();
      ViewBag.Releases = new SelectList(test.getID(), selectedId, "ID");
      ViewBag.Managers = new SelectList(test.getManagers(), Managers, "Managers");
      var que = test.getHello(selectedId, Managers);
      return View(que);
      }


      Index View Class:



       $(document).ready(function () {
      $("#Releases").on("change", function () {
      var value = $('#Releases :selected').text()
      $("#IDText").val(value);
      });
      $("#Managers").on("change", function () {

      var value = $('#Managers :selected').text()
      $("#ManagersText").val(value);
      });

      });
      @using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
      {
      <div class="container" id='div_release'>

      @Html.DropDownList("Releases", ViewBag.Releases as SelectList)
      @Html.DropDownList("Managers", ViewBag.Managers as SelectList)
      @Html.Hidden("IDText", "")
      @Html.Hidden("ManagersText", "")
      <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
      </div>
      }


      Selection View Class:



       <div class="container">
      <table id="myTable" align="left">
      <tr>
      <th>@Html.DisplayNameFor(model => model.ID)</th>
      <th>@Html.DisplayNameFor(model => model.Summary)</th>
      <th>@Html.DisplayNameFor(model => model.Description)</th>
      </tr>

      @foreach (var item in Model)
      {
      <tr id="Home">

      <td>@Html.DisplayFor(x => item.ID)</td>
      <td>@Html.DisplayFor(x => item.Summary)</td>
      <td>@Html.DisplayFor(x => item.Description)</td>
      </tr>
      }

      $(document).ready(function () {
      $("#Releases").on("change", function () {
      var value = $('#Releases :selected').text()
      $("#IDText").val(value);
      });
      $("#Managers").on("change", function () {

      var value = $('#Managers :selected').text()
      $("#ManagersText").val(value);
      });

      });
      @using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
      {
      <div class="container" id='div_release'>

      @Html.DropDownList("Releases", ViewBag.Releases as SelectList) // Getting the error here....
      @Html.DropDownList("Managers", ViewBag.Managers as SelectList)
      @Html.Hidden("IDText", "")
      @Html.Hidden("ManagersText", "")
      <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
      </div>
      }
      </table>
      </div>


      The error occurs in the Selection View Class. The View classes are almost identical, the only difference being is the data being displayed in the Selection View Class based on the selected value from the drop down list.










      share|improve this question















      Was receiving this error:



      An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code
      Additional information: DataBinding: 'Final.Models.Hello' does not contain a property with the name '700'.



      I looked through google for some answers, but I still feel lost.



      Model class:



      public Hello () {

      db = new ExtensionDBEntities();
      }

      public List<Hello> getID()
      {
      var que = (from rel in db.Table1
      select new Hello
      {
      ID = rel.ID
      }).ToList();
      return que;
      }

      public List<Hello> getStuff()
      {
      var que = (from wre in db.View
      select new Hello
      {
      ID = wre.ID,
      Summary = wre.Summary,
      Description = wre.Description

      }
      }


      getHello() is the same exact method as the getStuff(), just accepts a string ID parameter.



      Controller class:



      public ActionResult Index()
      {
      var model = test.getStuff();
      ViewBag.Releases = new SelectList(test.getID(), "", "ID");
      ViewBag.Managers = new SelectList(test.getManagers(), "", "Managers");
      return View("");
      }

      [HttpPost]
      public ActionResult Selection()
      {
      string selectedId = Request["IDText"].ToString();
      string Managers = Request["ManagersText"].ToString();
      var model = test.getStuff();
      ViewBag.Releases = new SelectList(test.getID(), selectedId, "ID");
      ViewBag.Managers = new SelectList(test.getManagers(), Managers, "Managers");
      var que = test.getHello(selectedId, Managers);
      return View(que);
      }


      Index View Class:



       $(document).ready(function () {
      $("#Releases").on("change", function () {
      var value = $('#Releases :selected').text()
      $("#IDText").val(value);
      });
      $("#Managers").on("change", function () {

      var value = $('#Managers :selected').text()
      $("#ManagersText").val(value);
      });

      });
      @using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
      {
      <div class="container" id='div_release'>

      @Html.DropDownList("Releases", ViewBag.Releases as SelectList)
      @Html.DropDownList("Managers", ViewBag.Managers as SelectList)
      @Html.Hidden("IDText", "")
      @Html.Hidden("ManagersText", "")
      <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
      </div>
      }


      Selection View Class:



       <div class="container">
      <table id="myTable" align="left">
      <tr>
      <th>@Html.DisplayNameFor(model => model.ID)</th>
      <th>@Html.DisplayNameFor(model => model.Summary)</th>
      <th>@Html.DisplayNameFor(model => model.Description)</th>
      </tr>

      @foreach (var item in Model)
      {
      <tr id="Home">

      <td>@Html.DisplayFor(x => item.ID)</td>
      <td>@Html.DisplayFor(x => item.Summary)</td>
      <td>@Html.DisplayFor(x => item.Description)</td>
      </tr>
      }

      $(document).ready(function () {
      $("#Releases").on("change", function () {
      var value = $('#Releases :selected').text()
      $("#IDText").val(value);
      });
      $("#Managers").on("change", function () {

      var value = $('#Managers :selected').text()
      $("#ManagersText").val(value);
      });

      });
      @using (Html.BeginForm("Selection", "Sample", FormMethod.Post))
      {
      <div class="container" id='div_release'>

      @Html.DropDownList("Releases", ViewBag.Releases as SelectList) // Getting the error here....
      @Html.DropDownList("Managers", ViewBag.Managers as SelectList)
      @Html.Hidden("IDText", "")
      @Html.Hidden("ManagersText", "")
      <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
      </div>
      }
      </table>
      </div>


      The error occurs in the Selection View Class. The View classes are almost identical, the only difference being is the data being displayed in the Selection View Class based on the selected value from the drop down list.







      javascript jquery ajax asp.net-mvc entity-framework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 19:06

























      asked Nov 7 at 17:25









      caitlinp

      656




      656
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Here is a link to a fiddle that combines the views into one: https://dotnetfiddle.net/5uCKhI



          This should help you. Please let me know if there is anything else.



          Controller/Model



          public class caitlinpRealViewModel
          {
          public List<SelectListItem> IDList { get; set; }
          public string selectedId { get; set; }
          public List<SelectListItem> ManagerList { get; set; }
          public string selectedManager { get; set; }
          }

          public class HomeController : Controller
          {
          public caitlinpRealViewModel SetupViewModel(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = new caitlinpRealViewModel();

          if (vm != null)
          {
          viewModel.selectedId = vm.selectedId;
          }
          else
          {
          viewModel.selectedId = "1";
          }

          SelectListItem listItem = new SelectListItem() { Text = "1", Value = "1" };
          SelectListItem listItem2 = new SelectListItem() { Text = "2", Value = "2" };
          List<SelectListItem> list = new List<SelectListItem>();
          list.Add(listItem);
          list.Add(listItem2);

          if (vm != null)
          {
          viewModel.selectedManager = vm.selectedManager;
          }
          else
          {
          viewModel.selectedManager = "1";
          }
          SelectListItem listItem3 = new SelectListItem() { Text = "aManager", Value = "1" };
          SelectListItem listItem4 = new SelectListItem() { Text = "bManager", Value = "2" };
          List<SelectListItem> list2 = new List<SelectListItem>();
          list2.Add(listItem3);
          list2.Add(listItem4);

          viewModel.IDList = list;
          viewModel.ManagerList = list2;

          return viewModel;
          }

          [HttpPost]
          public ActionResult Selection(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = SetupViewModel(vm);
          return View(viewModel);
          }

          public ActionResult Tut135()
          {
          caitlinpRealViewModel viewModel = SetupViewModel(null);
          return View(viewModel);
          }


          View 1



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Tut135</title>
          </head>
          <body>
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
          </div>
          }
          </body>
          </html>


          View 2 (Selection)



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Selection</title>
          </head>
          <body>
          <div class="container">
          <table id="myTable" align="left">
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
          </div>

          }
          </table>
          </div>
          </body>
          </html>





          share|improve this answer























          • Yes i realize that doesn't give me the error, but I also need the selected text to display in the drop down.. If i run the above code it gives me random values..
            – caitlinp
            Nov 7 at 20:23










          • For instance: selectedID: 700, Manager: Kate [Submit]...................... Dropdown after Submit = selectedID: 560, Manager: Random
            – caitlinp
            Nov 7 at 20:26












          • I changed my answer.
            – kblau
            Nov 7 at 21:54










          • I can help you with everything else. I got the same thing as you did. It is because, you are displaying the dropdowns in the second page in a different context than the first page.
            – kblau
            Nov 7 at 22:18












          • Thank you for the detailed answer, but I figured out the solution yesterday. Its among the same lines as yours. Definitely the same concept applied.
            – caitlinp
            Nov 8 at 14:33











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194691%2fhttp-exception-was-unhandled-by-user-code-in-mvc%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          Here is a link to a fiddle that combines the views into one: https://dotnetfiddle.net/5uCKhI



          This should help you. Please let me know if there is anything else.



          Controller/Model



          public class caitlinpRealViewModel
          {
          public List<SelectListItem> IDList { get; set; }
          public string selectedId { get; set; }
          public List<SelectListItem> ManagerList { get; set; }
          public string selectedManager { get; set; }
          }

          public class HomeController : Controller
          {
          public caitlinpRealViewModel SetupViewModel(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = new caitlinpRealViewModel();

          if (vm != null)
          {
          viewModel.selectedId = vm.selectedId;
          }
          else
          {
          viewModel.selectedId = "1";
          }

          SelectListItem listItem = new SelectListItem() { Text = "1", Value = "1" };
          SelectListItem listItem2 = new SelectListItem() { Text = "2", Value = "2" };
          List<SelectListItem> list = new List<SelectListItem>();
          list.Add(listItem);
          list.Add(listItem2);

          if (vm != null)
          {
          viewModel.selectedManager = vm.selectedManager;
          }
          else
          {
          viewModel.selectedManager = "1";
          }
          SelectListItem listItem3 = new SelectListItem() { Text = "aManager", Value = "1" };
          SelectListItem listItem4 = new SelectListItem() { Text = "bManager", Value = "2" };
          List<SelectListItem> list2 = new List<SelectListItem>();
          list2.Add(listItem3);
          list2.Add(listItem4);

          viewModel.IDList = list;
          viewModel.ManagerList = list2;

          return viewModel;
          }

          [HttpPost]
          public ActionResult Selection(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = SetupViewModel(vm);
          return View(viewModel);
          }

          public ActionResult Tut135()
          {
          caitlinpRealViewModel viewModel = SetupViewModel(null);
          return View(viewModel);
          }


          View 1



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Tut135</title>
          </head>
          <body>
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
          </div>
          }
          </body>
          </html>


          View 2 (Selection)



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Selection</title>
          </head>
          <body>
          <div class="container">
          <table id="myTable" align="left">
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
          </div>

          }
          </table>
          </div>
          </body>
          </html>





          share|improve this answer























          • Yes i realize that doesn't give me the error, but I also need the selected text to display in the drop down.. If i run the above code it gives me random values..
            – caitlinp
            Nov 7 at 20:23










          • For instance: selectedID: 700, Manager: Kate [Submit]...................... Dropdown after Submit = selectedID: 560, Manager: Random
            – caitlinp
            Nov 7 at 20:26












          • I changed my answer.
            – kblau
            Nov 7 at 21:54










          • I can help you with everything else. I got the same thing as you did. It is because, you are displaying the dropdowns in the second page in a different context than the first page.
            – kblau
            Nov 7 at 22:18












          • Thank you for the detailed answer, but I figured out the solution yesterday. Its among the same lines as yours. Definitely the same concept applied.
            – caitlinp
            Nov 8 at 14:33















          up vote
          1
          down vote













          Here is a link to a fiddle that combines the views into one: https://dotnetfiddle.net/5uCKhI



          This should help you. Please let me know if there is anything else.



          Controller/Model



          public class caitlinpRealViewModel
          {
          public List<SelectListItem> IDList { get; set; }
          public string selectedId { get; set; }
          public List<SelectListItem> ManagerList { get; set; }
          public string selectedManager { get; set; }
          }

          public class HomeController : Controller
          {
          public caitlinpRealViewModel SetupViewModel(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = new caitlinpRealViewModel();

          if (vm != null)
          {
          viewModel.selectedId = vm.selectedId;
          }
          else
          {
          viewModel.selectedId = "1";
          }

          SelectListItem listItem = new SelectListItem() { Text = "1", Value = "1" };
          SelectListItem listItem2 = new SelectListItem() { Text = "2", Value = "2" };
          List<SelectListItem> list = new List<SelectListItem>();
          list.Add(listItem);
          list.Add(listItem2);

          if (vm != null)
          {
          viewModel.selectedManager = vm.selectedManager;
          }
          else
          {
          viewModel.selectedManager = "1";
          }
          SelectListItem listItem3 = new SelectListItem() { Text = "aManager", Value = "1" };
          SelectListItem listItem4 = new SelectListItem() { Text = "bManager", Value = "2" };
          List<SelectListItem> list2 = new List<SelectListItem>();
          list2.Add(listItem3);
          list2.Add(listItem4);

          viewModel.IDList = list;
          viewModel.ManagerList = list2;

          return viewModel;
          }

          [HttpPost]
          public ActionResult Selection(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = SetupViewModel(vm);
          return View(viewModel);
          }

          public ActionResult Tut135()
          {
          caitlinpRealViewModel viewModel = SetupViewModel(null);
          return View(viewModel);
          }


          View 1



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Tut135</title>
          </head>
          <body>
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
          </div>
          }
          </body>
          </html>


          View 2 (Selection)



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Selection</title>
          </head>
          <body>
          <div class="container">
          <table id="myTable" align="left">
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
          </div>

          }
          </table>
          </div>
          </body>
          </html>





          share|improve this answer























          • Yes i realize that doesn't give me the error, but I also need the selected text to display in the drop down.. If i run the above code it gives me random values..
            – caitlinp
            Nov 7 at 20:23










          • For instance: selectedID: 700, Manager: Kate [Submit]...................... Dropdown after Submit = selectedID: 560, Manager: Random
            – caitlinp
            Nov 7 at 20:26












          • I changed my answer.
            – kblau
            Nov 7 at 21:54










          • I can help you with everything else. I got the same thing as you did. It is because, you are displaying the dropdowns in the second page in a different context than the first page.
            – kblau
            Nov 7 at 22:18












          • Thank you for the detailed answer, but I figured out the solution yesterday. Its among the same lines as yours. Definitely the same concept applied.
            – caitlinp
            Nov 8 at 14:33













          up vote
          1
          down vote










          up vote
          1
          down vote









          Here is a link to a fiddle that combines the views into one: https://dotnetfiddle.net/5uCKhI



          This should help you. Please let me know if there is anything else.



          Controller/Model



          public class caitlinpRealViewModel
          {
          public List<SelectListItem> IDList { get; set; }
          public string selectedId { get; set; }
          public List<SelectListItem> ManagerList { get; set; }
          public string selectedManager { get; set; }
          }

          public class HomeController : Controller
          {
          public caitlinpRealViewModel SetupViewModel(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = new caitlinpRealViewModel();

          if (vm != null)
          {
          viewModel.selectedId = vm.selectedId;
          }
          else
          {
          viewModel.selectedId = "1";
          }

          SelectListItem listItem = new SelectListItem() { Text = "1", Value = "1" };
          SelectListItem listItem2 = new SelectListItem() { Text = "2", Value = "2" };
          List<SelectListItem> list = new List<SelectListItem>();
          list.Add(listItem);
          list.Add(listItem2);

          if (vm != null)
          {
          viewModel.selectedManager = vm.selectedManager;
          }
          else
          {
          viewModel.selectedManager = "1";
          }
          SelectListItem listItem3 = new SelectListItem() { Text = "aManager", Value = "1" };
          SelectListItem listItem4 = new SelectListItem() { Text = "bManager", Value = "2" };
          List<SelectListItem> list2 = new List<SelectListItem>();
          list2.Add(listItem3);
          list2.Add(listItem4);

          viewModel.IDList = list;
          viewModel.ManagerList = list2;

          return viewModel;
          }

          [HttpPost]
          public ActionResult Selection(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = SetupViewModel(vm);
          return View(viewModel);
          }

          public ActionResult Tut135()
          {
          caitlinpRealViewModel viewModel = SetupViewModel(null);
          return View(viewModel);
          }


          View 1



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Tut135</title>
          </head>
          <body>
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
          </div>
          }
          </body>
          </html>


          View 2 (Selection)



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Selection</title>
          </head>
          <body>
          <div class="container">
          <table id="myTable" align="left">
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
          </div>

          }
          </table>
          </div>
          </body>
          </html>





          share|improve this answer














          Here is a link to a fiddle that combines the views into one: https://dotnetfiddle.net/5uCKhI



          This should help you. Please let me know if there is anything else.



          Controller/Model



          public class caitlinpRealViewModel
          {
          public List<SelectListItem> IDList { get; set; }
          public string selectedId { get; set; }
          public List<SelectListItem> ManagerList { get; set; }
          public string selectedManager { get; set; }
          }

          public class HomeController : Controller
          {
          public caitlinpRealViewModel SetupViewModel(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = new caitlinpRealViewModel();

          if (vm != null)
          {
          viewModel.selectedId = vm.selectedId;
          }
          else
          {
          viewModel.selectedId = "1";
          }

          SelectListItem listItem = new SelectListItem() { Text = "1", Value = "1" };
          SelectListItem listItem2 = new SelectListItem() { Text = "2", Value = "2" };
          List<SelectListItem> list = new List<SelectListItem>();
          list.Add(listItem);
          list.Add(listItem2);

          if (vm != null)
          {
          viewModel.selectedManager = vm.selectedManager;
          }
          else
          {
          viewModel.selectedManager = "1";
          }
          SelectListItem listItem3 = new SelectListItem() { Text = "aManager", Value = "1" };
          SelectListItem listItem4 = new SelectListItem() { Text = "bManager", Value = "2" };
          List<SelectListItem> list2 = new List<SelectListItem>();
          list2.Add(listItem3);
          list2.Add(listItem4);

          viewModel.IDList = list;
          viewModel.ManagerList = list2;

          return viewModel;
          }

          [HttpPost]
          public ActionResult Selection(caitlinpRealViewModel vm)
          {
          caitlinpRealViewModel viewModel = SetupViewModel(vm);
          return View(viewModel);
          }

          public ActionResult Tut135()
          {
          caitlinpRealViewModel viewModel = SetupViewModel(null);
          return View(viewModel);
          }


          View 1



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Tut135</title>
          </head>
          <body>
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Upload" />
          </div>
          }
          </body>
          </html>


          View 2 (Selection)



          @model Testy20161006.Controllers.caitlinpRealViewModel
          @{
          Layout = null;
          }

          <!DOCTYPE html>

          <html>
          <head>
          <meta name="viewport" content="width=device-width" />
          <title>Selection</title>
          </head>
          <body>
          <div class="container">
          <table id="myTable" align="left">
          @using (Html.BeginForm("Selection", "Home", FormMethod.Post))
          {
          <div class="container" id='div_release'>
          @Html.DropDownListFor(m => m.selectedId, new SelectList(Model.IDList, "Value", "Text"))
          @Html.DropDownListFor(m => m.selectedManager, new SelectList(Model.ManagerList, "Value", "Text"))
          <input type="submit" name="Submit" id="btnUploadData" class="btn btn-primary" value="Submit" />
          </div>

          }
          </table>
          </div>
          </body>
          </html>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 7 at 22:04

























          answered Nov 7 at 20:02









          kblau

          1,3331415




          1,3331415












          • Yes i realize that doesn't give me the error, but I also need the selected text to display in the drop down.. If i run the above code it gives me random values..
            – caitlinp
            Nov 7 at 20:23










          • For instance: selectedID: 700, Manager: Kate [Submit]...................... Dropdown after Submit = selectedID: 560, Manager: Random
            – caitlinp
            Nov 7 at 20:26












          • I changed my answer.
            – kblau
            Nov 7 at 21:54










          • I can help you with everything else. I got the same thing as you did. It is because, you are displaying the dropdowns in the second page in a different context than the first page.
            – kblau
            Nov 7 at 22:18












          • Thank you for the detailed answer, but I figured out the solution yesterday. Its among the same lines as yours. Definitely the same concept applied.
            – caitlinp
            Nov 8 at 14:33


















          • Yes i realize that doesn't give me the error, but I also need the selected text to display in the drop down.. If i run the above code it gives me random values..
            – caitlinp
            Nov 7 at 20:23










          • For instance: selectedID: 700, Manager: Kate [Submit]...................... Dropdown after Submit = selectedID: 560, Manager: Random
            – caitlinp
            Nov 7 at 20:26












          • I changed my answer.
            – kblau
            Nov 7 at 21:54










          • I can help you with everything else. I got the same thing as you did. It is because, you are displaying the dropdowns in the second page in a different context than the first page.
            – kblau
            Nov 7 at 22:18












          • Thank you for the detailed answer, but I figured out the solution yesterday. Its among the same lines as yours. Definitely the same concept applied.
            – caitlinp
            Nov 8 at 14:33
















          Yes i realize that doesn't give me the error, but I also need the selected text to display in the drop down.. If i run the above code it gives me random values..
          – caitlinp
          Nov 7 at 20:23




          Yes i realize that doesn't give me the error, but I also need the selected text to display in the drop down.. If i run the above code it gives me random values..
          – caitlinp
          Nov 7 at 20:23












          For instance: selectedID: 700, Manager: Kate [Submit]...................... Dropdown after Submit = selectedID: 560, Manager: Random
          – caitlinp
          Nov 7 at 20:26






          For instance: selectedID: 700, Manager: Kate [Submit]...................... Dropdown after Submit = selectedID: 560, Manager: Random
          – caitlinp
          Nov 7 at 20:26














          I changed my answer.
          – kblau
          Nov 7 at 21:54




          I changed my answer.
          – kblau
          Nov 7 at 21:54












          I can help you with everything else. I got the same thing as you did. It is because, you are displaying the dropdowns in the second page in a different context than the first page.
          – kblau
          Nov 7 at 22:18






          I can help you with everything else. I got the same thing as you did. It is because, you are displaying the dropdowns in the second page in a different context than the first page.
          – kblau
          Nov 7 at 22:18














          Thank you for the detailed answer, but I figured out the solution yesterday. Its among the same lines as yours. Definitely the same concept applied.
          – caitlinp
          Nov 8 at 14:33




          Thank you for the detailed answer, but I figured out the solution yesterday. Its among the same lines as yours. Definitely the same concept applied.
          – caitlinp
          Nov 8 at 14:33


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194691%2fhttp-exception-was-unhandled-by-user-code-in-mvc%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()