【问题标题】:RedirectToAction is not working correctly in SurfaceController?RedirectToAction 在 SurfaceController 中无法正常工作?
【发布时间】:2014-12-08 11:41:12
【问题描述】:

我正在向 SurfaceController 的“提交”操作提交表单。在保存数据后,它使用 MVC RedirectToAction 重定向到另一个操作“LeadContact”并将 Id 作为参数传递给它。在“LeadContact”模型中正在填充并传递给“LeadContact”视图。

不确定我的操作是否正确,但当“LeadContact”在浏览器中呈现时,它会修改 URL。浏览器显示像 http://name:50656/umbraco/Surface/HealthInsurance/LeadContact?leadOptionId=70 这样的 URL,而我希望它应该是

http://name:50656/HealthInsurance/LeadContact?leadOptionId=70

你能指导我纠正一下吗?以下是我的代码:

 public ActionResult Submit(FormCollection form)
        {

            //Some logic and later redirect to another action 'LeadContact'             

return RedirectToAction("LeadContact", new { leadOptionId = _id}); 
         }


 public ActionResult LeadContact(int leadOptionId)

        {
           MyViewModel model = new MyViewModel();         

           //Lines of code to populate data into model   

            return View("LeadContact", model);
        }

感谢您的帮助和分享。

【问题讨论】:

标签: asp.net-mvc-4 umbraco umbraco7


【解决方案1】:

在config\UrlRewriting.config中添加如下重写规则:

<add name="LeadContactRewrite"
  virtualUrl="^/HealthInsurance/LeadContact(.*)"
  rewriteUrlParameter="ExcludeFromClientQueryString"
  destinationUrl="~/umbraco/Surface/HealthInsurance/LeadContact?$1"
  ignoreCase="true" />

回收 IIS,您应该可以转到 http://name:50656/HealthInsurance/LeadContact?leadOptionId=70 并获得您想要的结果。

您也可以查看Custom MVC routing in Umbraco

【讨论】:

    猜你喜欢
    • 2012-06-14
    • 2021-12-16
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    相关资源
    最近更新 更多