In my project we have one partial view which is used to book details of a job. I have added new property WorkerID to model which is used in this partial view and main view. In the partial view using html.textboxfor i have added a field for workerid.
Model:
[Display(Name = "Worker Name")]
public Int32? WorkerID { get; set; }
[UIHint("CheckBoxNullable")]
[Display(Name = "Confirm Client")]
public bool ConfirmClient { get; set; }
[UIHint("CheckBoxNullable")]
[Display(Name = "Confirm Worker")]
public bool ConfirmWorker { get; set; }
[UIHint("CheckBoxNullable")]
[Display(Name = "Plan")]
public bool Plan { get; set; }
Partial View:
@model BookingsModel
<style>
div.k-edit-form-container {
width: auto;
}
</style>
<style>
.k-textbox {
width: 100% !important;
height: 34px !important;
}
.form-control {
padding: 0px 6px;
}
</style>
<div class="col-lg-11">
<ul class="errors alert alert-danger" style="display:none;"></ul>
<div class="form-group">
@Html.LabelFor(model => model.ShiftName)<span class="colon">:</span>
<label id="ShiftValue"></label>
</div>
<div class="form-group">
@Html.LabelFor(model => model.StartDate)<span class="colon">:</span>
@Html.EditorFor(model => model.StartDate)
@Html.ValidationMessageFor(model => model.StartDate, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.EndDate)<span class="colon">:</span>
@Html.EditorFor(model => model.EndDate)
@Html.ValidationMessageFor(model => model.EndDate, "", new { @class = "text-danger" })
</div>
<div class="form-group" id="AllowQuickFill">
@Html.LabelFor(model => model.WorkerID)<span class="colon">:</span>
@Html.EditorFor(model => model.WorkerID, new { @class = "form-control", @placeholder = "Select Worker", @style = "Width:100%;" })
<label>Confirm Client</label><span class="colon">:</span> <input type="checkbox" id="chkConfirmClient" name="ConfirmClient" value="0" />
<label>Confirm Worker</label><span class="colon">:</span> <input type="checkbox" id="chkConfirmWorker" name="ConfirmWorker" value="0" />
<label>Plan</label><span class="colon">:</span> <input type="checkbox" id="chkPlan" name="Plan" value="0" />
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
initializeCombo("WorkerID", "/Workers/GetDataForCombo?workerStatusTypeID=3");
});
</script>
The InitializeCombo is a method we have created which loads drop down box. Out of 4 new properties which i added in the model only value of workerid is not getting passed to controller. When i run the application WorkerID drop down is get loaded properly, for testing i placed alerts to get value from drop down when user changes or selects any worker and it gave proper notification also.
If i change workerId from TextBoxFor to EditorFor then it works fine, but in that case it is not allowing me to define WorkerID property in model as nullable and this property should be defined as nullable. In my project i have used TextBoxFor in almost all places where i want to load comboboxes in this way and it works fine. But i am not able to find out why it is not working in this instance.
Regards, Savan Parmar