vendredi 11 novembre 2016

How to return values from a view that are populated from a stored procedure using checkboxes

I have a stored procedure that is called and retuns a list of results to my view

namespace myproject.Models
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations;
    using System.Collections.Generic;


    public partial class CheckDirectReports_Result
    {

        [Key]
        public Guid? id { get; set; }
        public string NAME { get; set; }
        public string EMPLID { get; set; }
        public short EMPL_RCD { get; set; }
        public bool hasSignedOff { get; set; }
        public bool checkedoff { get; set; }
        public virtual IEnumerable<EMPLOYEE_DUE_DATE> DueDates { get; set; }
    }
}

dbContext:

public virtual ObjectResult<CheckDirectReports_Result>CheckDirectReports(string eMPLID)
{

    var eMPLIDParameter = eMPLID != null ?
        new ObjectParameter("EMPLID", eMPLID) :
        new ObjectParameter("EMPLID", typeof(string));

    ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 180;

    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<CheckDirectReports_Result>("CheckDirectReports", eMPLIDParameter);
    }

I can display my results in a view(with previous assistance from here) and added the checkbox to the view, but i am not sure how to bind the checkbox to the row, and need to have the user be able to select certain rows, populate additional information for the rows selected(dates and other checkboxes) and submit the form.

Here is some code from my controller, to display in the view:

var q = results.CheckDirectReports(EMPLID).ToList();
var signOffs = results.table1.ToList(); 
var dueDates = results.table2.ToList();

q.ForEach(a => {
            a.hasSignedOff = signOffs.Any(p => p.EMPLID == a.EMPLID);
            a.DueDates = dueDates.Where(e => e.table2 == a.EMPL_RCD && e.EMPLID == a.EMPLID).Take(3);
        });


       return View(q); 

And a snippet from my view:

@model  IEnumerable<myproject.Models.CheckDirectReports_Result>



@using (Html.BeginForm("Save", "Manager", FormMethod.Post))


@foreach(var c in Model) 
        {
            <tr>
                <td>@Html.CheckBox("checkedoff")</td>
                <td>@Html.DisplayFor(modelItem => c.NAME)</td>
                <td>@Html.Hidden(c.EMPLID)
                    @c.EMPLID </td>
                <td>@c.EMPL_RCD</td>
         }

Because the stored procedure just returns a list of results from a tables not in the database of my project, i am unsure how to proceed. I need to update the tales in my project based of the information displayed and the input data (i dont need help for this - i just need help getting the data to the controller)




Aucun commentaire:

Enregistrer un commentaire