{
private static string selection = String.Empty;
dynamic mymodel = new ExpandoObject();
public ActionResult Post(string Name)
{
selection = Name;
return RedirectToAction("Index");
}
public ActionResult Index()
{
SegmentRepository segment = new SegmentRepository();
mymodel.listofSegments = segment.GetSegmentation();
DynamicRepository dynamic = new DynamicRepository();
mymodel.listofDynamic = dynamic.GetDynamicContent(selection); //After selecting the segmentation in the view it returns the required dynamic content in mymodel.listofDynamic but does not display it in the view.
return View(mymodel);
}
}
在视图中选择的分割后,它返回所需要的动态内容在mymodel.listofDynamic
但确实不要在视图中显示它。
查看:
<script>
function seg() {
var employment = document.getElementById("Employment").value;
$.ajax({
type: "POST", //HTTP POST Method
url: '@Url.Action("Post","Home")', // Controller/View
data: {
//Passing data
Name: employment //Reading text box values using Jquery
}
})
}
</script>
<tr>
<td height="100">
<label>220</label>
</td>
<td>
<select id="Employment">
<option>---Select---</option>
@foreach (var item in Model.listofSegments)
{
<option name="selectedSegment" value="@item">@item</option>
}
</select>
<input type="submit" value="Send" name="submit" onclick="seg()">
</td>
<td>
<select name="Dynamic">
<option>---Select---</option>
@foreach (var item in Model.listofDynamic)
{
<option name="selectedDynamic" value="@item">@item</option>
}// I need the data to get listed here
</select>
<input type="submit" value="Send" name="Submit1">
</td>
</tr>
我需要的public ActionResult Index()
方法,以便在listofDynamic
数据视图获取打印再次运行。我怎样才能做到这一点?
你做了一个ajax调用 - ajax调用永远不会重定向(它们的全部重点是保持在同一页面上)。做一个正常的提交到你的'Post()'方法 –