我已经查看过这个问题的时间了,我已经实现了他们遇到的任何错误。然而,当我调用Ajax Actionlink时,我仍然会运行两个进程,并且涉及一个引导模式。以下是所有相关代码。我包括Bundle只显示其中一个不显眼的内容:
布局:
<div id="mainBody" class="container body-content">
@RenderBody()
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
控制器:
public ActionResult ReleaseVersion(string LOCATION_NUMBER = "")
{
...
model.ReleaseVersionVMInfo = rvmodel;
if (Request.IsAjaxRequest())
{
return PartialView("_ReleaseVersion", model);
}
return PartialView("_ReleaseVersion", model);
}
查看:
<div class="col-xs-3">
<div class="row Padding_ExtraVert">
@Ajax.ActionLink("Release Version",
"ReleaseVersion",
"Stores",
new { LOCATION_NUMBER = Model.storeNbr },
new AjaxOptions
{
UpdateTargetId = "ReleaseModal",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
OnFailure = "storeSearchFailed"
},
new
{
@class = "col-xs-5 btn btn-sm button-v
button-alt-1 Button_StoreHead",
@id = "BtnViewRelease",
data_target = "#ReleaseModal",
data_toggle = "modal"
})
</div>
查看此Actionlink正在调用的内容:
@model EpmPortal.Models.App.StoreReleaseVersionVM
@if(Model!= null&amp;&amp; Model.storeNbr!=“0”) { .... 关
感谢您的帮助
答案 0 :(得分:0)
当我运行以下命令并在动作ReleaseVersion中放置断点时,它只会执行一次此操作,因此只有一个进程。
控制器/型号:
public class StoreViewModel
{
public int storeNbr { get; set; }
}
public class HomeController : Controller
{
public PartialViewResult ReleaseVersion(string LOCATION_NUMBER = "")
{
return PartialView("_ReleaseVersion"); //, model
}
public ActionResult IndexValid4()
{
var storeViewModel = new StoreViewModel { storeNbr = 5 };
return View(storeViewModel);
}
部分文件夹中的部分视图_ReleaseVersion:
release version partial view
查看:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>IndexValid4</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
@*MAKE SURE to put the next script in*@
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript">
$(function () {
$('#LOCATION_NUMBER').click(function () {
var store = $('#storeNbr').val();
this.href = this.href.split("?")[0];
this.href = this.href + '?LOCATION_NUMBER=' + encodeURIComponent(store);
});
})
</script>
</head>
<body>
<div>
<a data-toggle="modal" data-target="#myModal">
Click to Open modal
</a>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">My Modal</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<label class="btnIEFix">You can also, Click in Grey Area Outside Modal To Close</label>
<button title="You can also, Click in Grey Area Outside Modal To Close" type="button" class="btn btn-secondary bootBtnMargin" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@Html.HiddenFor(r => r.storeNbr, new { id = "storeNbr" })
@*https://stackoverflow.com/questions/5838273/actionlink-routevalue-from-a-textbox*@
@Ajax.ActionLink(
"Trigger Ajax",
"ReleaseVersion",
null,
new AjaxOptions
{
UpdateTargetId = "result",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
},
new
{
id = "LOCATION_NUMBER",
@class = "col-xs-5 btn btn-sm button-vbutton-alt-1 Button_StoreHead",
data_target = "#myModal",
data_toggle = "modal"
}),
<div id="result"></div>
</body>
</html>
答案 1 :(得分:0)
哦,兄弟,事实证明它与我的预期完全不同。在我的程序的另一个分支中,我还没有真正开始工作,我在那里有一个局部视图,它从顶部的共享文件夹中有_Layout - 除了剃刀中的标题之外别无其他它。导致重复运行的原因。我不知道为什么。永远不会触及该代码。对此抱歉。