简体   繁体   English

使用ajax回调到服务器

[英]Callback to server using ajax

I am trying to do a callback to the server to return a partial view to my modal when i click the "Add Role" button, but nothing happens when I click the button. 当我单击“添加角色”按钮时,我试图对服务器进行回调以将部分视图返回到我的模式,但是当我单击该按钮时,什么也没有发生。

JavaScript: JavaScript的:

$(".addRole").on("click", function(){
  bootbox.dialog({
    title: "Create new role",
    callback: function () {
      $.ajax({
        url: "/Uam/CreateRole/",
        method: "POST",
        success: function(){}
      });
    }
  });
});

View: 视图:

@model List<Vidly.Models.AvailableRole>

@{
 ViewBag.Title = "CreateRole";
 Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Available Roles</h2>

<div id="addRoleForm">
  <button class="btn btn-success pull-right addRole"  type="button" data-toggle="modal">New Role</button>
</div>

Controller: 控制器:

public ActionResult CreateRole(int? id){
  if (id == null){
    var menuViewModel = new RoleMenuViewModel{
      Menus = GetMultiselectItems()
    };
  return View("SaveRole", menuViewModel);
  }

Message attribute is mandatory for bootbox dialog 消息属性对于Bootbox对话框是必需的

$(".addRole").on("click", function(){
  bootbox.dialog({
   message: '<p class="text-center">Please wait while Createing new role...</p>',
    title: "Create new role",
    callback: function () {
      $.ajax({
        url: "/Uam/CreateRole/",
        method: "POST",
        success: function(){}
      });
    }
  });
});

http://bootboxjs.com/examples.html#bb-custom-dialog http://bootboxjs.com/examples.html#bb-custom-dialog

I ended up using the basic bootstrap modal with a @html.RenderAction call in the modal body and a reference to the launch button. 我最终使用了基本引导程序模态,并在模态主体中使用了@ html.RenderAction调用,并引用了启动按钮。 No JQuery used. 没有使用JQuery。

<button id="addRole-btn" class="btn btn-success pull-right btn-lg" data-toggle="modal" data-target="#modal-container">New Role</button>


<div id="modal-container" class="modal fade" role="dialog" width="500px">
<div id="role-container"></div>
<div class="modal-content">
    <div class="modal-body">
        @if (true)
        {
            Html.RenderAction("CreateRole", "Uam");
        }
    </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM