Csharp/C#教程:不允许子操作执行重定向操作 – 使用ASP.NET MVC 2和Razor时出错分享


不允许子操作执行重定向操作 – 使用ASP.NET MVC 2和Razor时出错

_Layout.cshtml文件中,我有以下条目:

@Html.Action("LoadPagesStructure", "Page") 

PageController类中, LoadPagesStructure方法如下:

 [ChildActionOnly] /* this attribute indicates that an action should not be invoked as a result of a user request (by url) */ public ActionResult LoadPagesStructure() { ViewModel.Pages = new List() {"page1", "page2", "page3"}; return View(); } 

最后,我的LoadPagesStructure.cshtml视图如下所示:

 @inherits System.Web.Mvc.WebViewPage  

不幸的是,执行后会抛出exception:

 System.InvalidOperationException: Child actions are not allowed to perform redirect actions. 

动态创建链接到页面的方式是什么?

PS:我知道我可以这样做: https://stackoverflow.com/questions/3573554/child-actions-are-not-allowed-to-perform-redirect-actions-error-while-working/@page 。 不过我认为这不是正确的方法,因为这里不可能控制路由。

问候

我认为您可能需要为LoadPagesStructure()操作返回PartialView

试试这个:

上述就是C#学习教程:不允许子操作执行重定向操作 – 使用ASP.NET MVC 2和Razor时出错分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 [ChildActionOnly] public ActionResult LoadPagesStructure() { ViewModel.Pages = new List() {"page1", "page2", "page3"}; return PartialView(); } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1025707.html

(0)
上一篇 2022年1月8日
下一篇 2022年1月8日

精彩推荐