我有下面的表格,我想要做的是,当人们点击搜索按钮时,一个请求将文件传送到服务器,服务器将返回一组新的结果,并且我将重新渲染div到出现新的结果为什么AjaxForm不适合我?
@using (Ajax.BeginForm("Search", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "DivToUpdate" }))
{
<div style="margin: 10px 50px 5px 50px;">
@Html.TextBox("instrument", (string)ViewBag.DefaultInstrumentStr)
<input type="submit" value="Search" />
</div>
}
<div id="DivToUpdate" style="width: 100%; display: none;">
@if (Model != null)
{
@Html.Partial("_InstrumentList", @Model);
}
else
{
<span>Loading ....</span>
}
</div>
这里是我的控制器实现:
public ActionResult Search(string instrument)
{
// ... base on the input perform certain action to generate a list of result
return PartialView("_InstrumentList", instruments);
}
当我运行它,点击搜索后,我只能看到在浏览器中的局部视图,数据不更新div。
任何人都知道我做错了什么? 谢谢。
thx为你评论..我添加了unobtru sive-ajax.js .. – jojo
当在visual studio中开始调试时..我得到这个错误 Microsoft JScript运行时错误:无法设置属性'unobtrusive'的值:对象为null或undefined 并单击continue .. ..还是一样的东西 – jojo
查看我的评论回.. ..忘了重建..... – jojo