【问题标题】:why is the partial view not beeing replaced?为什么局部视图没有被替换?
【发布时间】:2012-11-25 13:52:31
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    当我显示 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 flag 设置为 false。

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

    这必须是 OFFCOURSE 为真! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-11
      • 2021-12-19
      • 2012-03-23
      • 1970-01-01
      • 2011-10-28
      • 2021-08-07
      • 2015-08-01
      • 2011-07-11
      相关资源
      最近更新 更多