更改ASP.NET MVC3中url的重定向操作链接
我想自动回邮到dropdownlist。 我的意见书:更改ASP.NET MVC3中url的重定向操作链接,.net,asp.net-mvc,asp.net-mvc-3,telerik,.net,Asp.net Mvc,Asp.net Mvc 3,Telerik,我想自动回邮到dropdownlist。 我的意见书: @using (Html.BeginForm("Index", "Model", FormMethod.Post)) { @(Html.Telerik().DropDownList() .Name("ddlBrands") .BindTo((IEnumerable<SelectListItem>)ViewData["brands"])
@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>
}
调用GET action之后
public ActionResult Index(int? ddlBrands)
{
SetBrandItems();
List<Model> m = dm.GetModelsByBrandId(ddlBrands).ToList();
return View(m);
}
公共行动结果索引(int?DDL品牌)
{
SetBrandItems();
List m=dm.GetModelsByBrandId(ddlBrands.ToList();
返回视图(m);
}
但我的页面不刷新,url不更改,数据不更新。。。
有人能帮我吗
我想自动回邮到dropdownlist。我的意见书:
@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>
}
执行标准表单提交:
function onDropDownListChange(e) {
$("form").submit();
}
并返回相同的视图(使用预填充模型):
还是想通过AJAX实现?如果是这样,请改用Ajax.Form:
@using (Ajax.BeginForm(...)) {
...
}
DropDownList更改事件是ajax操作。我认为您不能在服务器端重定向。但是您可以在ajax回调中添加一个redect 例如:
我很困惑,你不想刷新页面吗?或者你想刷新页面?我想刷新我的页面。但是如果你知道我的表格上有其他变量更新日期,请帮忙你的获取索引方法看起来怎么样你能指出你得到的问题吗,有错误吗?我没有错误。我的方法正确地获取和发送数据,但当我重定向时,调用下一个方法public ActionResult Index(int?ddlBrands)。一分钟-我编辑我的帖子
[HttpPost]
public ActionResult Index(string ddlBrands) {
SetBrandItems();
return View("Index", new { ddlBrands = ddlBrands });
}
@using (Ajax.BeginForm(...)) {
...
}
function SimpleAjaxRequest(url, requestData) {
return $.ajax(
{
type: 'POST',
url: url,
async: true,
data: { ddlBrands: requestData },
dataType: "json",
traditional: true,
success: function() {
//callback redirect
location.href = '/Model/Index';
}
});
}
[HttpPost]
public ActionResult Index(string ddlBrands)
{
SetBrandItems();
return Json(null, JsonRequestBehavior.AllowGet);
}