【发布时间】:2012-02-04 06:13:34
【问题描述】:
我想自动回发到下拉列表。 我的表单正在查看:
@using (Html.BeginForm("Index", "Model", FormMethod.Post))
{
@(Html.Telerik().DropDownList()
.Name("ddlBrands")
.BindTo((IEnumerable<SelectListItem>)ViewData["brands"])
.ClientEvents(events => events
.OnChange("onDropDownListChange")
)
)
<input type="submit" value="OK" />
<table style="margin:15px; margin-left:0px;">
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FullModel)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ModelID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ModelID })
</td>
</tr>
}
</table>
}
和javascript:
<script type="text/javascript">
function onDropDownListChange(e) {
SimpleAjaxRequest('/Model/Index', e.value);
}
function SimpleAjaxRequest(url, requestData) {
return $.ajax(
{
type: 'POST',
url: url,
async: true,
data: { ddlBrands: requestData },
dataType: "json",
traditional: true
});
}
</script>
我通过 Ajax 将 Post 数据从 Index 视图发送到服务器,在处理数据后,我需要更新表单上的数据。我该怎么做?我正在尝试重定向到 POST 操作
[HttpPost]
public ActionResult Index(string ddlBrands)
{
SetBrandItems();
return RedirectToAction("Index", "Model", new {ddlBrands = ddlBrands});
}
调用 GET 操作后
public ActionResult Index(int? ddlBrands)
{
SetBrandItems();
List<Model> m = dm.GetModelsByBrandId(ddlBrands).ToList();
return View(m);
}
但是我的页面没有刷新,url 没有改变,数据没有更新...... 有人可以帮帮我吗?
【问题讨论】:
-
我很困惑,您不想刷新页面吗?或者您希望页面刷新?
-
我想刷新我的页面。但如果你知道其他变体来更新我的表格上的日期,请帮助
-
你的 GET 索引方法是什么样子的
-
你能指出你遇到的问题,有什么错误吗?
-
我没有错误。我的方法正确地接收和发送数据,但是当我重定向调用下一个方法公共 ActionResult 索引(int?ddlBrands)。一分钟 - 我编辑我的帖子
标签: .net asp.net-mvc asp.net-mvc-3 telerik