为什么局部视图没有被替换?

时间:2012-12-07 11:29:02

标签: ajax asp.net-mvc asp.net-mvc-partialview unobtrusive

从演示解决方案中我尝试使用内置的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>

1 个答案:

答案 0 :(得分:0)

当我显示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的unobtrusive标志设置为false。

  <appSettings>
    <add key="ClientValidationEnabled" value="true"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="false"/> 
  </appSettings>

这必须OFFCOURSE为真! :)