![](/img/trans.png)
[英]Child actions are not allowed to perform redirect actions. (Using PartialViews)
[英]doesn't work redirecttoaction in partial view controller.(Error - Child actions are not allowed to perform redirect actions.)
不允许子操作执行重定向操作。 我在哪里需要设置代码?
我在另一个控制器中尝试过redirecttoaction。 有用。 但它在menucontroller中不起作用。 那是我的问题。 请告诉我正确的方向。
```In layout inside of share folder.
<body id="backGroundColor">
<div class="row">
<div class="col-lg-12" style="text-align:center;background-color:#e6ffff;color:#007bff;font-weight:bold; font-size:30px;font-family:'Times New Roman', Times, serif">
<div class="col-lg-1">
<img src="~/wwwroot/Image/bfe.png" alt="logo" style="width:180px;height:70px;font-weight:bold;">
</div>
<div class="col-lg-11">
Management System
</div>
</div>
<div class="col-lg-12">
<nav class="navbar navbar-inverse navbar-fixed" id="navmenu" style="width:100%">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navbar-fixed-Middle" id="myNavbar" >
@Html.Action("MenuLayout", "Menu")
</div>
</div>
</nav>
</div>
</div>
<br /><br />
<div class="container-fluid ">
<div>
@RenderBody()
</div>
</div><br />
<footer id="forFooter" style="z-index: 10;">
<p>© @System.DateTime.Now.Year -Copyright WMS 8.0.0</p>
</footer>
```In MenuController
public ActionResult MenuLayout()
{
if (cRoldId == null)
{
return RedirectToAction("Create", "Issue");
}
}
//Instead of this,
@Html.Action("MenuLayout", "Menu")
//you should use
@Html.Partial("partial1", "Controller1")
//You should create two partial _MenuPartial and CreatePartial
//In your Shared/Layout
@if(cRoldId == null)//or any other condition depending of your variable
{
@Html.Partial("MenuLayout", "MenuController")
}
else
{
@Html.Partial("Create", "Issue")
}
如果您在加载页面或任何其他事务后需要执行此操作,则可以使用ajax调用:
在您的菜单控制器中:
public ActionResult MenuLayout(string cRoldId)
{
if (cRoldId == null)
{
return PartialView("Create"); //Create must be in the controllers folder.
}
else
{
return PartialView("MenuLayout"); //menu layout must be a partial view.
}
}
<script type="text/javascript">
//Executes on load event of the document
$(document).load(function(){
function printProjectFiles() {
$.ajax({
url: '@Url.Action("MenuLayout", "Menu")',//MenuLayout is your method name, Menu is your controller name
type: 'GET',
data: {cRoldId :"yourParamValue"},
dataType: 'HTML',
success: function (result) {
$("#myNavbar").html(result);//returns a partial view and inserts it into your control.
},
error: function (err) {
}
});
}
});
</script>
告诉我它是否有效。
而不是@Html.Action("MenuLayout", "Menu")
在您的视图中,
尝试使用@Url.Action("MenuLayout", "Menu")
对我来说,这对我前段时间遇到的类似情况起了作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.