[英]Get database Value in textboxFor in bootstrap modal popup in MVC
I place a text box in the bootstrap modal popup and also I have a kink in the table data in the table come from database so I want when I click pop-up show database cell value in the textbox that exists in the modal-popup. 我在引导程序模式弹出窗口中放置了一个文本框,并且在表中的数据中有一个纽结,该表来自数据库,因此我想当我在模式弹出窗口中存在的文本框中单击弹出显示数据库单元格值时使用。 Below is my code
下面是我的代码
Thats my action method that gets data and data is passing to the ViewBag.Type 那就是我获取数据和数据的操作方法正在传递给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);
}
Here is a code of JQuery and Ajax acall the action method on link click 这是JQuery和Ajax的代码,它们在链接单击时调用action方法
<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>
Here is textBox in the Modal PopUp 这是模式弹出窗口中的文本框
@Html.TextBoxFor(model => model.RoleType, new { @value=ViewBag.Type })
You can return your data like bellow, 您可以像下面这样返回数据,
return this.Json(new { result = true, Type = data.RoleType },
JsonRequestBehavior.AllowGet);
Then in your ajax success method, you can retrieve the value like, 然后,在您的ajax成功方法中,您可以检索类似的值,
success:function(data)
{
var _result = data.result;
var _Type = data.Type ;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.