I have generated dynamic input fields grid and I want to bind to controller but I have tried many times but failed.When I submit the form then show null object on controller action.
Model class which is bound to the view; all properties name is accurately written in input fields names.
public class PvitalsDetails
{
public Int64 PatientVitalId { get; set; }
public Int64 PatientId { get; set; }
public int VitalsInformationId { get; set; }
public string Unit { get; set; }
public string ImageUrl { get; set; }
public string Readings { get; set; }
public string Time { get; set; }
}
This is the view
@model List<PKLI.Model.Emr.PvitalsDetails>
<form role="form" action="@Url.Action("PatientVitals", "EMR")" method="post" id="FormVitals" onsubmit="return SubmitVitalFieldValues();">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Vitals/Measurement</th>
<th>Values</th>
<th>Unit</th>
<th>Time Taken</th>
</tr>
</thead>
<tbody>
@foreach (PKLI.Model.Emr.PvitalsDetails item in ViewBag.Vitals)
{
<tr>
<td>
<input type="hidden" name="VitalsInformationId" value="@item.VitalsInformationId" />
@item.Name
</td>
<td><input placeholder="@item.Name" type="text" name="Readings" class="form-control" /></td>
<td>
@item.Unit
<input type="hidden" name="Unit" /> </td>
<td>
<input type="text" name="Time"
class="form-control"
placeholder="Enter Time" data-mask="99:99" />
</td>
</tr>
}
</tbody>
</table>
</div>
<input type="submit" class="btn btn-green" value="submit"/>
<form>
Controller:
public ActionResult PatientVitals(List<PvitalsDetails> pvitalsDetails)
{
var id = 0;
var enterBy = SessionHelper.GetLoggedInUserId();
var patientVitals = new PatientVitals();
var patient = (Session["Patient"] as Patient) ?? new Patient();
var response = new AjaxResponse
{
Code = 400,
MessageClass = "warning",
ResponseText = "Unable to process"
};
return response;
}