C# 使用mvc局部视图和history.js
我正在使用history js和Mvc部分视图,下面是我的代码 在部分主屏幕中C# 使用mvc局部视图和history.js,c#,asp.net-mvc,history.js,C#,Asp.net Mvc,History.js,我正在使用history js和Mvc部分视图,下面是我的代码 在部分主屏幕中 <a id="CreateUser" class="btn btn-primary">Create User </a> 在contoller中,如果调用ajax,也可以加载部分视图;如果没有调用,则加载完整视图。这是为了防止用户在~/System/user/Create/中按refresh时受到影响。 无论我的脚本在节中的onClick脚本在从局部视图或Ajax调用的/System/user
<a id="CreateUser" class="btn btn-primary">Create User </a>
在contoller中,如果调用ajax,也可以加载部分视图;如果没有调用,则加载完整视图。这是为了防止用户在~/System/user/Create/中按refresh时受到影响。
无论我的脚本在节中的onClick脚本在从局部视图或Ajax调用的/System/user中不起作用,我都可以通过在@section脚本内部附加onClick事件来解决这个问题,所以它变成这样:
<a id="CreateUser" class="btn btn-primary">Create User </a>
<script>
$('#back').click(function (e) {
History.pushState({ state: 1 }, "Create User", "/System/User/Create/");
});
</script>
@section scripts
{
<script>
$('#back').click(function (e) {
History.pushState({ state: 1 }, "Create User", "/System/User/Create/");
});
</script>
}
创建用户
$(“#返回”)。单击(函数(e){
pushState({state:1},“创建用户”,“系统/用户/创建/”);
});
@节脚本
{
$(“#返回”)。单击(函数(e){
pushState({state:1},“创建用户”,“系统/用户/创建/”);
});
}
但这是多余的,维护起来很痛苦,我知道会发生这种情况,因为@section不适用于Ajax/Partial,无论如何,除了它之外还有更干净的替代方案。别担心。单击“加载Ajax后需要重新绑定,但使用.on”('click'不需要重新绑定事件处理程序,所以我现在只需要全局js中click事件的脚本
<a id="CreateUser" class="btn btn-primary">Create User </a>
<script>
$('#back').click(function (e) {
History.pushState({ state: 1 }, "Create User", "/System/User/Create/");
});
</script>
@section scripts
{
<script>
$('#back').click(function (e) {
History.pushState({ state: 1 }, "Create User", "/System/User/Create/");
});
</script>
}