C# 单击后在同一页的特定div中加载我的部分视图
我有这个密码C# 单击后在同一页的特定div中加载我的部分视图,c#,jquery,asp.net,asp.net-mvc,razor,C#,Jquery,Asp.net,Asp.net Mvc,Razor,我有这个密码 [AcceptVerbs(HttpVerbs.Get)] public ActionResult ManageEmployee(int cntID, string command) { repository = new ContactRepository(); if (!String.IsNullOrEmpty(command) && command.Equals("edit")) { LKIContact employees
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult ManageEmployee(int cntID, string command)
{
repository = new ContactRepository();
if (!String.IsNullOrEmpty(command) && command.Equals("edit"))
{
LKIContact employees = repository.GetById(cntID);
ViewBag.IsUpdate = true;
return PartialView("_ManageEmployee", employees);
}
else
{
ViewBag.IsUpdate = false;
return PartialView("_ManageEmployee");
}
}
当我点击:
<a href='Home/ManageEmployee?cntID=${cntID}&command=edit' class='editDialog'>Edit</a>
下面是加载网格的代码,以及希望加载表单的div的位置
@section featured {
<section class="featured">
<div class="content-wrapper">
<!-- the igHierarchicalGrid target element-->
<table id="employeeGrid" style="width: auto;"></table>
<p>
<!--<a id='openDialog' href='Home/CreateEmployee?cntID=0' class='openDialog ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' style="color: white;"><button>Add Employee</button></a>-->
</p>
</div>
</section>
<br />
<div id="dialog-confirm" style="display: none">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure to delete ?
</p>
</div>
<div id="dialog-edit"></div>
<div id="dialog-view" style="display: none"></div>
}
感谢您的帮助您可以使用ajax调用获取局部视图并在div中渲染:
<script type="text/javascript">
$(document).on("click", "#btnEdit", function () {
$.ajax({
url: "Home/ManageEmployee?cntID=" + myEmployeeID + "&command=edit";
cache: false,
success: function (html) {
$("#dialog-edit").append(html);
}
});
});
</script>
在页面底部添加此脚本,将btnEdit替换为编辑按钮的id,并将MyEmployeeID替换为要编辑的employeeid。如果每行都有一个编辑按钮,则可能会将employeeid包含在链接标记中,例如作为数据属性
<a href='Home/ManageEmployee?cntID=${cntID}&command=edit' data-employeeid='${cntID}' class='editor'><button>Edit</botton></a>
然后使用来自afzalulh的示例,只需获取数据属性
<script type="text/javascript">
$(document).on("click", ".editor", function () {
var myEmployeeID = $(this).data('employeeid');
$.ajax({
url: "Home/ManageEmployee?cntID=" + myEmployeeID + "&command=edit";
cache: false,
success: function (html) {
$("#dialog-edit").append(html);
}
});
});
</script>
检查从服务器获取HTML并将其填充到DOM中。您提到网格的每一行都有编辑按钮。你能发布网格的标记吗?您可以编辑您的问题并向其添加代码。对不起,我的答案对igGrid没有多大帮助。谢谢您的帮助,但遗憾的是,没有得到所需的结果
<script type="text/javascript">
$(document).on("click", ".editor", function () {
var myEmployeeID = $(this).data('employeeid');
$.ajax({
url: "Home/ManageEmployee?cntID=" + myEmployeeID + "&command=edit";
cache: false,
success: function (html) {
$("#dialog-edit").append(html);
}
});
});
</script>