简体   繁体   English

代码仍会在新页面上加载内容

[英]Code still loads content on new page

Hi I have problem with my MVC application. 嗨,我的MVC应用程序有问题。 I would like click on ActionLink > load data from server > and insert data to div in same page. 我想点击ActionLink>从服务器加载数据>并在同一页面中将数据插入div。 But my code still loads content on new page and I don`t have idea why. 但我的代码仍然在新页面加载内容,我不知道为什么。 Anybody to help me ? 有人帮我吗?

This is my Index.cshtml in HomeController, 这是我在HomeController中的Index.cshtml,

    @model IEnumerable<Kango_kmen.KangoKmenWS.WSEntityInfo>
    @Content.Script("jquery-1.9.1.min.js", Url)
    @Content.Script("jquery.unobtrusive-ajax.min.js",Url)
    @Content.Script("jquery.unobtrusive-ajax.js",Url)
    @Content.Script("myScript.js",Url)

    @section Entities{


    <table>
    <tr>
    <th>
      <input type="submit" value="zobrazit" />
    </th>
    <th>
        iD
    </th>
    <th>
        name
    </th>

    </tr>

    @foreach (var item in Model) {
    <tr>
    <td>
    @Ajax.ActionLink("..", "CheckEntity", new { id = item.iD }, 
            new AjaxOptions{ UpdateTargetId="properties",
                             HttpMethod="GET",
                             InsertionMode=InsertionMode.InsertAfter,
            })
    </td>
    <td>            
        @Html.DisplayFor(modelItem => item.iD)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.name)
    </td>

    </tr>  
    <tr>
     <td>
         <div id="properties">

         </div>
     </td>
    </tr>
     }
    </table>
     }


     @section PropertyInfo{
     <p>Property info</p>
     } 

     @section Properties{
     <p>properties</p>
     }

And here is my Controller in HomeController 这是我在HomeController中的控制器

    public PartialViewResult CheckEntity(int id)
    {

        var model = WSConnect.getEntityInfo(id);
        if(model !=null){
            return PartialView("CheckEntity", model.property);
        }
        var modell = new WSEntityInfo[0];
        return PartialView("CheckEntity", modell);
    }

and ChecktEntity is the Partial view but everytime I click on ActionLink controller load url: /Home/ChceckEntity/1000 for exmaple on view data on this new page "( 和ChecktEntity是部分视图,但每次我点击ActionLink控制器加载url:/ Home / ChceckEntity / 1000以获取此新页面上的视图数据“(例如

There are 2 things wrong with your code: 您的代码有两个问题:

  1. You have included the jquery.unobtrusive-ajax.js script twice, once the minified version and once the standard version. 您已经将jquery.unobtrusive-ajax.js脚本包含两次,一次是缩小版本,一次是标准版本。 You should include it only once 你应该只包括一次
  2. The jquery.unobtrusive-ajax.js is not compatible with jquery 1.9.1 because one of the breaking changes in jQuery 1.9 is that the .live() method was removed and the jquery.unobtrusive-ajax.js script relies on it. jquery.unobtrusive-ajax.js with jquery 1.9.1不兼容with jquery 1.9.1因为jQuery 1.9中的一个重大变化是删除.live()方法并且jquery.unobtrusive-ajax.js脚本依赖于它。 If you look at your javascript console you would see the following error: The .live method is undefined. 如果你看一下你的javascript控制台,你会看到以下错误: The .live method is undefined. . So if you want to use the unobtrusive AJAX functionality in ASP.NET MVC you will have to downgrade the version of jQuery. 因此,如果您想在ASP.NET MVC中使用不显眼的AJAX功能,则必须降级jQuery的版本。 For example the 1.8.3 version should be fine. 例如, 1.8.3版本应该没问题。

So: 所以:

@model IEnumerable<Kango_kmen.KangoKmenWS.WSEntityInfo>
@Content.Script("jquery-1.8.3.min.js", Url)
@Content.Script("jquery.unobtrusive-ajax.min.js", Url)
@Content.Script("myScript.js", Url)

Also please learn how to debug your javascript code. 另请注意如何调试您的JavaScript代码。 Use a tool such as FireBug or Chrome developer toolbar where all those errors will be shown. 使用FireBug或Chrome开发人员工具栏等工具,可以显示所有这些错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 页面由于js代码而加载两次 - page loads twice due to js code 如何动态识别母版页中的内容页面负载? - How to identify content page loads in a master page dynamically? 奇怪的内容和已删除的页面仍然可以在Umbraco中查看 - Strange Content and Deleted page is still viewable in Umbraco 页面加载时禁用“添加新记录”按钮 - Disable "Add New Record" Button when page loads 页面完全加载后如何显示来自代码背后的警报? - How to show alert from code behind after page loads completely? 如何为内容页面自定义母版页代码 - how to customize master page code for content page 当我创建新员工时,下拉列表不加载数据,但是刷新页面时它将加载新数据 - Dropdown is not loading data while I create new employee but when the page is refreshed it loads the new data 切换到新页面,仍然显示未填写表格的错误半秒钟 - Changing to a new page, still showing errors of unfilled form for half a second 为什么页面加载时我的Tabstrip菜单显示所有内容? - Why does my Tabstrip menu show all its content when the page loads? 在Internet Explorer 7和7+版本中,Asp.net页面加载了奇怪的内容 - Asp.net page loads with weird content in Internet explorer 7 & 7+ versions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM