我有通过按钮点击打开的模态窗口
以下是View中的代码:
<button style="margin-bottom: 20px;" class="btn btn-default" data-toggle="modal" data-target="#myModal">Описание вакансии</button>
<div class="modal fade" id="myModal" role="dialog" data-backdrop="false">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Описание</h4>
</div>
<div class="modal-body">
@Html.Partial("~/Views/Questions/Info.cshtml")
</div>
</div>
</div>
这是模态代码:
<div id="detail">
</div>
<script>
$(document).ready(function() {
emaillist_update2();
});
function emaillist_update2() {
var url = window.location.pathname;
var id = url.substring(url.lastIndexOf('/') + 1);
$.ajax({
url:'@Url.Action("Displayinfo2","Questions")',
type: 'Post',
dataType: 'Json',
data: {
ID: id
},
success: function(result) {
var info = result;
$("#detail").append(info.Greeting);
},
error: function(result) {
alert('Error');
}
});
}
</script>
Maodal是部分视图
我在modal中的脚本中的问题无法在打开的地方工作。看起来它在页面加载时起作用,而不是模态。
打开模态时如何运行它?
答案 0 :(得分:1)
您就是这样做的:
视图中的部分视图共享名为_Info.cshtml:
<svg width="210px" height="210px" viewBox="0 0 210 210" class="donut">
<circle class="donut-ring" cx="105" cy="105" r="95" fill="transparent" stroke="black" stroke-width="20"></circle>
<circle class="donut-segment" cx="105" cy="105" r="95" fill="transparent" stroke="#1a1a1a" stroke-width="20" stroke-dasharray="149.22565104551518 447.67695313654554" stroke-dashoffset="150"></circle>
<circle class="donut-segment" cx="105" cy="105" r="95" fill="transparent" stroke="#333333" stroke-width="20" stroke-dasharray="149.22565104551518 447.67695313654554" stroke-dashoffset="597.6769531365455"></circle>
<circle class="donut-segment" cx="105" cy="105" r="95" fill="transparent" stroke="#434343" stroke-width="20" stroke-dasharray="298.45130209103036 298.45130209103036" stroke-dashoffset="448.45130209103036"></circle>
</svg>
控制器/型号:
A Partial View
<div id="detail" />
查看:
public class MyDataModel
{
public int ID { get; set; }
}
//Create an edmx to your table
public class HomeController : Controller
{
[HttpPost]
public ActionResult Index2005(string ID)
{
return Json(new
{
Greeting = "This is a Greeting"
}
, @"application/json");
}
public ActionResult Index2005(int? id) //argument to differ from post
{
return View();
}