简体   繁体   English

如何以jquery对话框模型形式或引导弹出窗口显示CRUD视图

[英]How to display CRUD views in a jquery dialog model form, or in a bootstrap popup

 <script src="jquery-js"> $("._detailsInfo").click( function () { var Id = $(this).attr('Id'); $.ajax({ "url": "/Test/Details/"+Id, "type": "GET", "dataType": "html", success: function (response) { $('#myModal').modal(options); $('#myModal').modal('show'); }, failure: function (response) { alert(response.responseText); } }); }); </script> 

 @model BOL3.tbl_Appoiment_Diary <div class="modal fade" id="myModal" role="dialog" tabindex="-1"> <div class="modal-dialog"> <div class="modal-header"> <button type="button" class="close" data-dissmiss="modal" aria-hidden="true">x</button> <h4 class="modal-title" id="myModalLabel">Details</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.Title) </dt> <dd> @Html.DisplayFor(model => model.Title) </dd> </dl> </div> <p> @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) | @Html.ActionLink("Back to List", "Index") </p> </div> </div> 

 <td> @*@Html.ActionLink("Details", "Details", new { id = item.ID }) |*@ <button class="btn btn-info btn btn-xs _detailsInfo" id=" '+ item.ID +' ">Details</button> | @Html.Partial("_Details", new BOL3.tbl_Appoiment_Diary()) @*@Html.ActionLink("Details", "_Details", new { @class = "_detailsInfo", id = "'+item.ID+'" }) |*@ </td> 

Can anyone help me with this. 谁能帮我这个。 Please keep in mind that I'm quite new working with Javascript and Jquery so any help is greatly appreciated. 请记住,我使用Javascript和Jquery还是一个新手,因此非常感谢您的帮助。 I tryied different methods from multiple websites but nothing worked. 我尝试了来自多个网站的不同方法,但没有任何效果。 Here are some of the websites that I tryed: 这是我尝试过的一些网站:

jquery-dialog-with-aspnet-mvc , jquery-dialog , and many others, but nothing seems to work. jquery-dialog-with-aspnet-mvcjquery-dialog和许多其他名称,但似乎没有任何作用。

Here is what i tryed until now: 这是我到目前为止尝试过的:

public ActionResult Details(int Id)
     {
         BOL3.tbl_Appoiment_Diary appd = new BOL3.tbl_Appoiment_Diary();
         appd = db.tbl_Appoiment_Diary.Find(Id);
         return PartialView("_Details", appd);
     }

this is the controller part. 这是控制器部分。

 <script src="jquery-js"> //$(function () { // $("#dialog").dialog({ // autoOpen: false, // modal: true, // title: "Details" // }); // $("#AppoimentDiary .details").click(function () { // var ID = $(this).closest("tr").find("td").eq(0).html(); // $.ajax({ // type: "POST", // url: "/Test/Details/", // data: '{ID: "' + ID + '"}', // contentType: "application/json; charset=utf-8", // dataType: "html", // success: function (response) { // $('#dialog').html(response); // $('#dialog').dialog('open'); // }, // failure: function (response) { // alert(response.responseText); // }, // error: function (response) { // alert(response.responseText); // } // }); // }); //}); //$(document).ready(function () { // $("#btnCreate").click(function () { // InitializeDialog($("#testdialog")); // $("#testdialog").dialog("open"); // }); // function InitializeDialog($element) { // $.dialog({ // autoOpen: false, // width: 400, // resizable: true, // draggable: true, // title: "Appointments", // model: true, // show: 'slide', // closeText: 'x', // dialogClass: 'alert', // closeOnEscape: true, // open: function (event, ui) { // $element.load('/Test/Add'); // }, // close: function () { // $(this).dialog('close'); // } // }); // } //}); //$.ajaxSetup({ cache: false }); //$(document).ready(function () { // $(".openPopup").live("click", function (e) { // e.preventDefault(); // $("<div></div><p>") // .addClass("dialog") // .attr("id", $(this) // .attr("data-dialog-id")) // .appendTo("body") // .dialog({ // title: $(this).attr("data-dialog-title"), // close: function () { $(this).remove(); }, // modal: true, // height: 250, // width: 900, // left: 0 // }) // .load(this.href); // }); // $(".close").live("click", function (e) { // e.preventDefault(); // $(this).closest(".dialog").dialog("close"); // }); //}); @*var url = '@Url.Action("Details", "Test")'; $('selector').load(url, { id: 1 });*@ </script> 
  @Html.ActionLink("Det", "Details", new { id = item.ID, @class = "data-toggle = 'modal' data-target = '#myModal' " }) | <div id="dialog" style="display: none"> </div> </div> @*<div id='myModal' class='modal'> <div class="modal-dialog"> <div class="modal-content"> <div id="myModalContent"></div> </div> </div> </div> <script src="jquery-js"> var TeamDetailPostBackURL = '/Test/Details'; $(function () { $(".anchorDetail").click(function () { debugger; var $buttonClicked = $(this); var id = $buttonClicked.attr('data-id'); var options = { "backdrop": "static", keyboard: true }; $.ajax({ type: "GET", url: TeamDetailPostBackURL, contentType: "application/json; charset=utf-8", data: { "Id": id }, datatype: "json", success: function (data) { debugger; $('#myModalContent').html(data); $('#myModal').modal(options); $('#myModal').modal('show'); }, error: function () { alert("Loading the data is not possible!"); } }); }); $("#closbtn").click(function () { $('#myModal').modal('hide'); }); }); </script>*@ @*<div class="modal fade" id="myModal" role="dialog" tabindex="-1"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header" style="background-color:aqua"> <h4 class="modal-title">Ada New</h4> </div> <div class="modal-body"> @Url.Action("/Test/Details") </div> <div class="modal-footer" style="background-color:aqua"> <button type="button" class="btn btn-danger" data-dissmiss="modal">Close</button> <button type="button" data-dismiss="modal" class="btn btn-success">Save</button> </div> </div> </div> </div>*@ 

Any help on this topic is greatly appreciated. 对此主题的任何帮助将不胜感激。

Edit : 编辑

This is the index button, the script is from your answer: 这是索引按钮,脚本来自您的答案:

in the same index view, and here is the partial view: 在相同的索引视图中,这是部分视图:

See, there is no need to call again details method from your modal body. 请参阅,无需从模态主体再次调用details方法。

Create a modal inside partial view, and keep all your partial view HTML inside the modal body. 在部分视图内创建一个模态,并将所有部分视图HTML保留在模态主体内。 And in top of your partial view, add your modal reference , like bellow, 在部分视图的顶部, 添加模式引用 ,例如波纹管,

@model Your_Project_Name.ModalFolderName.tbl_Appoiment_Diary

<div class="modal fade" id="myModal" role="dialog" tabindex="-1">
 <div class="modal-dialog">
  <div class="modal-header">Details Info</div>
   <div class="modal-body">
    /*Here keep your all HTML to display details data*/
   </div>
  </div>
 </div>

Change or update the above HTML accordingly. 相应地更改或更新上述HTML。 And change the reference name with your project name and class name. 并用您的项目名称和类名称更改引用名称。

Create your Details button in your main view, like this, 在主视图中创建“详细信息”按钮,如下所示,

<button class="btn btn-info _detailsInfo" id="'+item.ID+'"></Details>

While click this button call a jquery click function like bellow, 当点击此按钮时,将调用jello单击功能,例如波纹管,

$("._detailsInfo").click(function () 
 {
  var Id = $(this).attr('Id');
  $.ajax({
        "url": "/Test/Details/"+Id,
        "type": "Get",
        "dataType": "html",
        success: function (response) {
                   $('#myModal').modal(options);
                   $('#myModal').modal('show');
                },
        failure: function (response) {
                    alert(response.responseText);
               }
           });
    });

Suppose your partial view name is _Details.cshtml. 假设您的部分视图名称是_Details.cshtml。 Then just render it inside your main view like this,(basically keep this bellow code before the close tag of body of your main view) 然后像这样将其呈现在您的主视图中(基本上将下面的代码保留在主视图主体close标签之前)

@Html.Partial("_Details", new tbl_Appoiment_Diary())

That's it! 而已! Hope it helps you. 希望对您有帮助。

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

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