[英]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: 您的代码有两个问题:
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 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.
The .live method is undefined.
. 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.