从一个演示解决方案中,我尝试使用内置的 mvc ajax 功能。但出于某种原因,部分视图没有被取代。
@using (Ajax.BeginForm("RefreshPartial", "Home", new AjaxOptions() { UpdateTargetId = "PartialToRefresh", HttpMethod = "Post" }))
{
@Html.TextBox("Name");
<input type="submit" value="Send name" />
}
<br />
<div>
@Ajax.ActionLink("Just refresh", "RefreshPartial", "Home", null, new AjaxOptions() { UpdateTargetId = "PartialToRefresh", HttpMethod = "Post" }, null)
</div>
<br />
<div id="PartialToRefresh">
@Html.Partial("_DateTimePartial", "test")
</div>
当我显示HTML页面时,我得到了这个html代码
<form action="/Home/RefreshPartial" id="form0" method="post" onclick="Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));" onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'Post', updateTargetId: 'PartialToRefresh' });">
<input id="Name" name="Name" type="text" value="">
<input type="submit" value="Send name">
</form>
经过一番谷歌搜索,我发现web.config将不显眼的标志设置为false。
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="false"/>
</appSettings>
这一定是真的! :)