I have a dropdownlist in my parent view and when I select a value I want to save that value and use it when I click a button in my partial view. Currently if I click a button in the partial view it will not have the value of the parent view. However, if I move the dropdownlist to the partial view everything works fine, but I would like to keep it in my parent view.
Parent View (This is where the dropdownlist is)
<div class="btn-toolbar">
<div class="btn-group">
<button type="button" class="btn btn-primary" id="FetchProcessId">Fetch Process Id</button>
</div>
</div>
<div class="col-md-3" style="@displayAdminLead">
<div class="dropdown div-inline">
@{
var envlist = new List<SelectListItem>()
{
new SelectListItem() {Value = "OAK", Text = "OAK"},
new SelectListItem() {Value = "QA", Text = "QA"},
new SelectListItem() {Value = "PROD", Text = "PROD"}
};
}
@Html.DropDownListFor(m => m.EnvironmentName, envlist, "Environment", new {@class = "form-control"})
</div>
</div>
<div style="overflow: auto">
@using (Html.BeginForm())
{
<div id="FetchProcessIdDiv" style="">
@Html.Action("FetchProcessId", Model)
</div>
}
</div>
Partial View
<table class="table table-hover">
<tbody>
<tr>
<td>System Name:</td>
<td>
@Html.DropDownListFor(m => m.FetchProcessIdModel.SystemName, new SelectList(Model.FetchProcessIdModel.DropDownOptions, "valueId", "value"))
</td>
<td rowspan="2">@Html.TextAreaFor(m => m.FetchProcessIdModel.Message, 12, 50, null)</td>
</tr>
<tr>
<td>Deliverable Id:</td>
<td>@Html.TextBoxFor(m => m.FetchProcessIdModel.DeliverableId)</td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" class="btn btn-default" value="Fetch Process Id" />
Parent Model
public class ParentModel
{
public string EnvironmentName { get; set; }
}
Controller
[HttpPost]
public ActionResult ParentClass(string submit, ParentModel model)
{
//omit
var envName = model.EnvironmentName;
//I am not seeing a value for model.EnvironmentName at this point
}