0

This is my view model that contain the list visitor

    public class CreatePreVisitors
        {
            public List<Hosts> hosts = new List<Hosts>();
            public List<PreVisitors> visitorList = new List<PreVisitors>();
            public PreVisitors visitor = new PreVisitors();
        }

This is my view in which I used the model create visitor and in this model i have already filled the hosts from backend . what I wanted to do is to fill and return visitor list that is being filled in my view by text boxes, or return create visitor viewmodel with my visitor list being filled

@model  BLL.ViewModels.CreatePreVisitors
<h2>AddPreVisitor</h2>

<div class="row">
    <div class="form-group col-md-12">
        <h5 style="font-weight: bold;">Register User</h5>

        @using (Html.BeginForm("addMultipleVisitor", "PreVisitor", FormMethod.Post, new { id = "Visitor-form" }))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary()
        <div><a href="#" id="addNew">Add New</a></div>
    <div class="table-responsive">
        <table class="table table-bordered" id="dataTable">

            <tr >
                <th>NIC</th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Address</th>
                <th>Company</th>
                <th>Contact No</th>
                <th>Host</th>
                <th>Host Email</th>
                <th>From Date</th>
                <th>to Date</th>
                <th>Time</th>
                @*<th></th>*@
            </tr>

            @if (Model.visitorList != null && Model.visitorList.Count > 0)
{
    int j = 0;
    foreach (var i in Model.visitorList)
    {
        <tr style="border:1px solid" >
            <td>@Html.TextBoxFor(a =>Model.visitorList[j].VNIC, new {@class=" form-control"}) </td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].VfirstName, new { @class = " form-control" })</td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].VlastName, new { @class = " form-control" })</td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].Vaddress, new { @class = " form-control" })</td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].Vcompany, new { @class = " form-control" })</td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].VphoneNo, new { @class = " form-control" })</td>
            <td>@Html.DropDownListFor(a => Model.visitorList[j].host_id, new SelectList(Model.hosts, "EmpID", "hFirst", 0), new {@class="form-control"})</td>

            <td>@Html.TextBoxFor(a => Model.visitorList[j].host_email, new { @class = " form-control" })</td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].from_Date, new { @class = "datepicker form-control" })</td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].to_date, new { @class = "datepicker form-control" })</td>
            <td>@Html.TextBoxFor(a => Model.visitorList[j].Time, new { @class = "timepicker form-control" })</td>
            @*<td>
                @if (j > 0)
                {
                    <a href="#" class="remove">Remove</a>
                }
            </td>*@
        </tr>

                j++;
    }
}
        </table>
    </div>
            <input type="submit" id="vv" value="Save Bulk Data" />

        }
</div>

and this is my controller where it comes on submit and I wanted to list of visitor . can any one help me what should I do ??

  [HttpPost]
        public ActionResult addMultipleVisitor(List<BLL.ViewModels.PreVisitors> PreVisitors)
        {
            BLL.PreVisitors.addMultipleVisitor(PreVisitors);
            return RedirectToAction("addMultipleVisitor");
        }
Abdul Muqeet
  • 201
  • 2
  • 11

0 Answers0