在 MVC 中的 bootstrap 模式弹出窗口中获取 textboxFor 中的数据库值
Get database Value in textboxFor in bootstrap modal popup in MVC
我在 bootstrap 模式弹出窗口中放置了一个文本框,而且 table 中的数据来自数据库,因此我希望在单击弹出窗口时有一个扭结-up 在模式弹出窗口中存在的文本框中显示数据库单元格值。下面是我的代码
这就是我获取数据的操作方法,数据正在传递给 ViewBag.Type
public JsonResult LinkButton(int RoelID)
{
Role model = new Role();
Session["State"] = RoelID;
int id = RoelID;
RoleServices ser = new RoleServices();
var data = ser.Get(id);
bool result=false;
if(Session["State"]!=null)
{
ViewBag.Type = data.RoleType;
result=true;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
这是 JQuery 的代码,Ajax 在 link 单击
时调用操作方法
<a href="#" onclick="UpdateID(@item.RoelID)">Select</a>
<script>
var UpdateID = function (RoelID) {
$("#hiddenID").val(RoelID);
var roleID=$("#hiddenID").val();
$.ajax({
type: "post",
url: '@Url.Action("LinkButton", "Account")',
data: { RoelID: roleID },
success:function()
{
$("moReg").modal('hide');
}
})
$("#moReg").modal('show');
}
</script>
这是模态弹出窗口中的文本框
@Html.TextBoxFor(model => model.RoleType, new { @value=ViewBag.Type })
您可以 return 您的数据如下所示,
return this.Json(new { result = true, Type = data.RoleType },
JsonRequestBehavior.AllowGet);
然后在您的 ajax 成功方法中,您可以检索像这样的值,
success:function(data)
{
var _result = data.result;
var _Type = data.Type ;
}
我在 bootstrap 模式弹出窗口中放置了一个文本框,而且 table 中的数据来自数据库,因此我希望在单击弹出窗口时有一个扭结-up 在模式弹出窗口中存在的文本框中显示数据库单元格值。下面是我的代码
这就是我获取数据的操作方法,数据正在传递给 ViewBag.Type
public JsonResult LinkButton(int RoelID)
{
Role model = new Role();
Session["State"] = RoelID;
int id = RoelID;
RoleServices ser = new RoleServices();
var data = ser.Get(id);
bool result=false;
if(Session["State"]!=null)
{
ViewBag.Type = data.RoleType;
result=true;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
这是 JQuery 的代码,Ajax 在 link 单击
时调用操作方法<a href="#" onclick="UpdateID(@item.RoelID)">Select</a>
<script>
var UpdateID = function (RoelID) {
$("#hiddenID").val(RoelID);
var roleID=$("#hiddenID").val();
$.ajax({
type: "post",
url: '@Url.Action("LinkButton", "Account")',
data: { RoelID: roleID },
success:function()
{
$("moReg").modal('hide');
}
})
$("#moReg").modal('show');
}
</script>
这是模态弹出窗口中的文本框
@Html.TextBoxFor(model => model.RoleType, new { @value=ViewBag.Type })
您可以 return 您的数据如下所示,
return this.Json(new { result = true, Type = data.RoleType },
JsonRequestBehavior.AllowGet);
然后在您的 ajax 成功方法中,您可以检索像这样的值,
success:function(data)
{
var _result = data.result;
var _Type = data.Type ;
}