0

I am VERY new to MVC.

I am using .NET core 2.0 with EntityFrameworkCore. I have my contexts established and data, models, controllers, views all working at the most basic level.

I have model/view/controller for HRIS data and model/view/controller for Entity (not Entity Framework) data (among others).

Entity model contains company, division, location, contract, etc.

On the HRIS view Index.cshtml page I need to pull all entities that are of type contract and populate a <select> which will then determine which contract the HRIS data is related to. Example: User sees contract select and picks Contract1. All future actions in this view will reference HRIS data associated with Contract1.

Basic flow scheme:

  1. User enters New Contract in Entity View.
  2. User goes to HRIS view and selects Contract from Select.
  3. User imports HRIS data from text file that will be associated with that Contract.
  4. User proceeds to view/model/controller to edit imported HRIS data.

I realize that my code must handle the actual import and associating the data with the contract. I'm just trying to find out how to populate the <select> within the confines of MVC while the Contract data is in the Entity model and not in the HRIS model.

I've allowed the framework to create <select> controls for other items in the application using:

<select asp-for="EntityTypeID" class="form-control" asp-items="ViewBag.EntityTypeID"></select>

and

ViewData["EntityTypeID"] = new SelectList(_context.EntityTypes, "EntityTypeID", "EntityTypeName");

and this works very well but these are within the same model.

Important note: after data is imported, it will be handled completely by another view/model/controller if that makes any difference in how this is handled.

Any suggestions would be appreciated.

John
  • 819
  • 1
  • 9
  • 20
  • Your actually using asp.net-core-mvc –  Sep 25 '17 at 02:06
  • Its not really clear what you struggling with. And it would help if you showed your models and the controller method view where your wanting to create the ` –  Sep 25 '17 at 02:14
  • And as a side note,do not use the same name for the property your binding to and the `SelectList` (refer [Can the ViewBag name be the same as the Model property name in a DropDownList?](https://stackoverflow.com/questions/37161202/can-the-viewbag-name-be-the-same-as-the-model-property-name-in-a-dropdownlist/37162557#37162557)). And do not use data models in your view - use a view model - refer [What is ViewModel in MVC?](https://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc) –  Sep 25 '17 at 02:16
  • And for a typical example of how generating a ` –  Sep 25 '17 at 02:18

0 Answers0