我的控制器在应用程序启动时加载结果部分视图 "SOMETIMES"
my controller loads the Resulting Partial View "SOMETIMES" at application launch
我有一个包含 .CSHTML 视图的主机页面,当我们单击 Grid 元素时,它最终会调用局部视图。但是,有时当我启动我的应用程序时,它首先会尝试加载局部视图。我不确定这是为什么?
它必须仅在单击网格上的元素时才尝试加载局部视图,但此处它在未单击的情况下调用局部视图。按照我的代码片段:
!DOCTYPE html>
@using (Html.BeginForm())
{
<div id="clientsDb">
@(Html.Kendo().Grid<Employee>()
.Name("employeeGrid")
.Columns(columns =>
{
columns.Bound(c => c.Id).Width(140).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(c => c.FirstName).Width(500).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(c => c.LastName);
})
.HtmlAttributes(new {style = "height: 380px;"})
.Scrollable()
.Groupable()
.Sortable()
.Selectable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Filterable(filterable => filterable
.Extra(true)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.IsEqualTo("Exactly matches")
.StartsWith("Starts with")
.DoesNotContain("Does not contain")
.EndsWith("Ends with")
.IsNotEqualTo("Is not equal to")
))).DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("ReadEmployee", "Employee"))))
</div>
<script type="text/javascript">
$("#employeeGrid").click(function() {
var grid = $("#employeeGrid").data("kendoGrid");
var currentSelection = grid.dataItem(grid.select());
$.ajax({
data: { id: currentSelection.Id },
url: "/Employee/LoadTabControl/" + currentSelection.Id,
type: "POST",
success: function (result) {
$('#EmployeeDetails').html(result);
}
});
});
</script>
<div id ="EmployeeDetails"></div>
如您所见,“”/Employee/LoadTabControl/”或它加载的任何内容在用户单击 GRID 之前不应调用。但是,应用程序正在尝试加载它 "Sometimes"当我启动应用程序时。有什么建议吗?
<script type="text/javascript">
$(document).ready(function(){
var grid = $("#employeeGrid").data("kendoGrid");
$("#employeeGrid").click(function() {
var currentSelection = grid.dataItem(grid.select());
$.ajax({
data: { id: currentSelection.Id },
url: "/Employee/LoadTabControl/" + currentSelection.Id,
type: "POST",
success: function (result) {
$('#EmployeeDetails').html(result);
}
});
});
});
</script>
我有一个包含 .CSHTML 视图的主机页面,当我们单击 Grid 元素时,它最终会调用局部视图。但是,有时当我启动我的应用程序时,它首先会尝试加载局部视图。我不确定这是为什么?
它必须仅在单击网格上的元素时才尝试加载局部视图,但此处它在未单击的情况下调用局部视图。按照我的代码片段:
!DOCTYPE html>
@using (Html.BeginForm())
{
<div id="clientsDb">
@(Html.Kendo().Grid<Employee>()
.Name("employeeGrid")
.Columns(columns =>
{
columns.Bound(c => c.Id).Width(140).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(c => c.FirstName).Width(500).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
columns.Bound(c => c.LastName);
})
.HtmlAttributes(new {style = "height: 380px;"})
.Scrollable()
.Groupable()
.Sortable()
.Selectable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Filterable(filterable => filterable
.Extra(true)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.IsEqualTo("Exactly matches")
.StartsWith("Starts with")
.DoesNotContain("Does not contain")
.EndsWith("Ends with")
.IsNotEqualTo("Is not equal to")
))).DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("ReadEmployee", "Employee"))))
</div>
<script type="text/javascript">
$("#employeeGrid").click(function() {
var grid = $("#employeeGrid").data("kendoGrid");
var currentSelection = grid.dataItem(grid.select());
$.ajax({
data: { id: currentSelection.Id },
url: "/Employee/LoadTabControl/" + currentSelection.Id,
type: "POST",
success: function (result) {
$('#EmployeeDetails').html(result);
}
});
});
</script>
<div id ="EmployeeDetails"></div>
如您所见,“”/Employee/LoadTabControl/”或它加载的任何内容在用户单击 GRID 之前不应调用。但是,应用程序正在尝试加载它 "Sometimes"当我启动应用程序时。有什么建议吗?
<script type="text/javascript">
$(document).ready(function(){
var grid = $("#employeeGrid").data("kendoGrid");
$("#employeeGrid").click(function() {
var currentSelection = grid.dataItem(grid.select());
$.ajax({
data: { id: currentSelection.Id },
url: "/Employee/LoadTabControl/" + currentSelection.Id,
type: "POST",
success: function (result) {
$('#EmployeeDetails').html(result);
}
});
});
});
</script>