我在索引上有这个代码,当我点击它我想调用编辑部分表格并传递参数
if (e.item.name == "btnHeaderCreatePassword") {
var index = UsersGrid.GetFocusedRowIndex();
// Call partial view from controller
}
我的控制器
public ActionResult EditHeaderFormPartial(string ObjId)
{
var user = db.Users.Where(c=>c.Id == ObjId).SingleOrDefault();
if (user == null)
{
ViewData["isEdit"] = false;
return PartialView("UsersEditPartialFormView", new User());
}
ViewData["isEdit"] = true;
return PartialView("UsersEditPartialFormView", user);
}
目的是通过单击btnHeaderCreatePassword作为弹出窗口调用EditHeaderFormPartial
答案 0 :(得分:0)
在主视图中,使用div(您需要加载局部视图)
<div id="loadpartialview"></div>
现在写一个ajax
$("#btnclick").click(function () {
path = "/controller/Actionmethod";
$.ajax({
type: "GET",
url: path,
success: function (dataval) {
$('#loadpartialview').html(dataval);
}
});
} else {
alert("Field Empty");
}
});
希望这会有所帮助。
答案 1 :(得分:0)
UsersEditPartialFormView是我想用输入调用的表单,我想在此时传递ObjId我从UI获取空对象ID
public ActionResult changepassword(string ObjId)
{
var user = db.Users.Where(c => c.Id == ObjId).SingleOrDefault();
if (user == null)
{
ViewData["isEdit"] = false;
return PartialView("UsersEditPartialFormView", new User());
}
ViewData["isEdit"] = true;
return PartialView("UsersEditPartialFormView", user);
}
所以当点击btnHeaderCreatePassword时,我得到所选行的值 并调用下面的ajax方法
if (e.item.name == "btnHeaderCreatePassword") {
var index = UsersGrid.GetFocusedRowIndex();
$.ajax({
dataType: "html",
type: "GET",
url: '@Url.Action("changepassword", "users")',
cache: false,
data: { userId: userId },
success: function (data) {
// UsersGrid.Refresh();
$('#UsersEditPartialFormView').html(dataval);
// alert("Got you");
},
error: function (xhr, textStatus, errorThrown) {
alert('Request Status: ' + xhr.status + '; Status Text: ' + textStatus + '; Error: ' + errorThrown);
}
});
}