Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Calling action through JQuery in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 294
    Comment on it

    In MVC projects you need to make AJAX call multiple times in your project .

     

    So for doing that you need to first include the Jquery file and its CSS into your view and into your project.

     

    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
    <link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />

     

     

    After doing this you need to make sure that you have made a function for invoking the controller action.

     

    $(".lnkEdit").live("click", function (e) {
                var id = $(this).attr('id');
                 url = '@Url.Content("~/Home/_Edit")/' + id;
                $("#dialog-edit").dialog('open');
                $.get(url,function (result) {
                    alert(result);
                     $("#dialog-edit").html(result);
                });
    
                // e.preventDefault(); use this or return false
                $(".ui-dialog-title").html("Update User");
                $("#dialog-edit").dialog('open');
                return false;
            });
    
    


     

       <a class="lnkEdit" id='@item.EmpId'>Edit</a>

     

    This will invoke the partial view named Edit in the Home controller.

     

     [HttpGet]
            public ActionResult _Edit(int id = 0)
            {
    
                EmpMod = new EmployeeModel();
                EmpMod.EmpId = id;
                EmpRep = new EmployeeRepository();
                EmpMod = EmpRep.EditDetails(EmpMod);
                return PartialView("_Edit", EmpMod);
    
            }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: