【问题标题】:How to handle situation when error happens during posting form from view user control?如何处理从视图用户控件发布表单期间发生错误的情况?
【发布时间】:2008-12-07 00:45:22
【问题描述】:

我有一个可以发布表单的视图用户控件。此控件可用于多个视图。 如果用户输入无效数据,我会向 ModelState 添加错误 - 就这么简单。问题是 我不知道要返回哪个视图/操作结果,因为我不知道用户从哪里发布表单。好的,我可以得到 urlreferer - 但这对我来说看起来不太好。有什么想法吗?

【问题讨论】:

    标签: asp.net-mvc viewusercontrol


    【解决方案1】:

    将信息从您的父页面传递给控制器​​。

    <% RenderPartial("MyUserControl", new MyUserControlViewData()
    {
        // pass parent page info here for user control to redirect to such as
        Controller = "Home",
        Action = "Index"
    
       // or even better
       ParentPath = ((WebFormView)this.ViewContext.View).ViewPath
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 2017-09-27
      • 1970-01-01
      • 2018-03-18
      • 1970-01-01
      • 2021-01-06
      相关资源
      最近更新 更多