我有一个视图,我想通过更改 DropDownList 来更改其数据。一切正常,但视图没有用新的数据集渲染。换句话说,当我将数据发布到控制器中的操作方法时,它无法返回视图。这是我的代码:
看法:
@model IEnumerable<Model.Params>
<table>
@foreach(var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
}
</table>
<div>
@(Html.Kendo().DropDownList()
.Name("datetime")
.DataTextField("DateText")
.DataValueField("DateText")
.Events(e => e.Change("datesChange"))
.DataSource(ds => ds.Read("Read_Intervals", "MyController"))
)
</div>
<script>
function datesChange() {
var value = $("#datetime").val();
$.post("@Url.Action("Kq_Read", "MyController")" + "?date=" + value);
}
</script>
控制器:
public ActionResult Kq(string date)
{
IQueryable<Params> kq;
if (date != null)
{
var datetime = Convert.ToDateTime(date);
kq = db.Params.Where(p => p.LogDate == datetime);
}
else
{
var datetime = GetLatestInterval();
kq = db.Params.Where(p => p.LogDate == datetime);
}
return View("Kq", kq);
}
[HttpPost]
public ActionResult Kq_Read(string date)
{
var datetime = Convert.ToDateTime(date);
var kq = db.Params.Where(p => p.LogDate == datetime);
return View("Kq", kq);
}