lundi 3 avril 2017

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

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

<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 })

Aucun commentaire:

Enregistrer un commentaire