Как отправить значение из формы, MVC, C#, linq, SQL
Hi A bit help with MVC, thank you How to submit values from Form with Enumerable<project.model.classA> into a class B ? I displayed values from Entity A with groupby (Name) command I changed the DisplayFor control for a EditFor control to set values and it will allow the system to submit them. //that's what I think. class CallRecord - I got his values by uploading a file and inserting those values into each matched column on this class +-------+------+--------------+ |Id | Name | Cost | +-------+------+--------------+ | 1 | Anna | 30.3 | +-------+------+--------------+ | 2 | Anna | 500 | +-------+------+--------------+ | 3 | Sam | 30.3 | +-------+------+--------------+ | 4 | Tom | 20.5 | +-------+------+--------------+ | 5 | Tom | 20.5 | +-------+------+--------------+ | 6 | Anna | 20.5 | +-------+------+--------------+ Grouped result values for class CallRecord: Grupdby Name Name Cost Anna 550.8 Sam 30.3 Tom 41 but I added a selectList for each displayed grouped result Name Cost Place Anna 550.8 select place = Place is a list added to each displayed value Sam 30.3 select place = Place is a list added to each displayed value Tom 41 select place = Place is a list added to each displayed value after user select Place value for each displayed on list user is allow to save save = if sumbit it pass all values to class RegisterCall class Place Id Name class RegisterCall Id Fname Place Desire result after submited from Index with a @model IEnumerable<project.Model.CallRecord> to the entity class RegisterCall class RegisterCall +-------+------+--------------+ |Id |Fname | Place | +-------+------+--------------+ | 1 | Anna | London | +-------+------+--------------+ | 2 | Sam | Paris | +-------+------+--------------+ | 5 | Tom | 20.5 | +-------+------+--------------+ //Thank you
Что я уже пробовал:
private ReportContext db = new ReportContext(); RegisterCall regcall= new RegisterCall(); CallRecord callrecord= new CallRecord(); // GET: Bill public ActionResult Index() { ViewBag.BUSelectedList = new SelectList(db.BUnitLists, "Id", "BUName"); return View(db.VariableVoices.ToList()); } // Post: Bill [HttpPost] public ActionResult BillSubmit(CallRecord callrecords) { //how pass values from displayed values on page to class RegisterCall } //Get BilView public ActionResult BilView() { return View(db.BillMaps.ToList()); }
@using (Html.BeginForm("BillSubmit", "Bill", FormMethod.Post)) { <table class="table table-bordered"> <thead> <tr> <th class="text-center"> Name </th> <th class="text-center"> Cost </th> <th class="text-center">Place</th> </tr> </thead> @foreach (var item in Model.GroupBy(un => un.fname, (key, items) => new { fname= key, Cost = items.Sum(u => u.Cost) })) { <tbody> <tr> <td> @Html.EditorFor(modelItem => item.fname, ) </td> <td> @Html.EditorFor(modelItem => item.Cost) </td> <th> @Html.DropDownList("PlaceList", (IEnumerable<SelectListItem>)ViewBag.PlaceSelectList, "Select Business Unit", new { @class = "form-control" }) @Html.ValidationMessage("PlaceList", "", new { @class = "text-danger" }) </th> </tr> </tbody> } </table> <div> <input type="submit" value="SAVE" class="navbar-btn btn-primary" /> </div> }