I have a main view with a textbox and dropdown list:
@using (Ajax.BeginForm("GetResults", "SomeController", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "PartialDiv" }))
<select name ="dropdown1" onchange="$(this.form).submit();" >
<option></option>
@foreach (var recordrow in ...)
{
<option value="@recordrow.Value" >@recordrow.Text</option>
}
</select>
<select name ="dropdown2" >
<option></option>
@foreach (var recordrow in ...)
{
<option value="@recordrow.Value" >@recordrow.Text</option>
}
</select>
@Html.TextBox("textbox1", null, new { size = 10 })
<div id="PartialDiv" class="GroupBoxForeground" >
@Html.Partial("PartialView")
</div>
The main view automatically renders a partial view once certain controls on the main view have been filled with values. Inside the Partial View, there is a submit button which calls an ActionResult.
Part of the Partial View:
@using (Ajax.BeginForm("Function1", "SomeController", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "someDiv" }))
...
<input type="submit" name="btn_submit" value="Process" style="width:80px" />
My ActionResult looks like this:
[HttpPost]
public ActionResult Function1(FormCollection formdata, MasterModel MstModel)
{
...
}
I am able to successfully bind the values in my Partial View to MasterModel. However, I am unable to get the values of the controls in the Main View while calling the ActionResult. I cannot find the key in the FormCollection and have tried the same method I used in the partial view for model binding.
Both Views are strongly-typed with the MasterModel.
Since the values in the Main View can be changed after the Partial View is rendered, I need to get the values once more when the submit button is clicked in the partial view. Is there a way to access those control values in the Main View inside ActionResult of the Partial View?
Edit: To explain the situation more clearly as suggested in the comments, My main view is basically a search screen with a textbox and one of the dropdown lists which will be used by the partial view for processing later.
My partial view (in a separate form) shows the results of the search along with a submit button inside to process certain tasks based on the results. However, this processing also requires the 2nd dropdown list's value and the textbox's value in the main view. Those 2 controls in the main view can be changed even after the partial view is loaded. Therefore, I am hoping to find some way to get those values in the main view when the submit button is pressed.
unable to get the values of the controls in the Main View
because those controls are not even inside the posted form. It is little unclear what you are trying to achieve. Try to explain clearly, so that people can suggest solutions – Zeeshan