RedirectToAction is not working correctly in SurfaceController?

浪子不回头ぞ 提交于 2019-12-25 04:23:17

问题


I m submiting a form to SurfaceController's action 'Submit'. Where after saving data it Redirect to another action 'LeadContact' using MVC RedirectToAction and pass Id as a paramter to it. In 'LeadContact' model is being populating and passed to 'LeadContact' view.

Not sure if I m doing correctly or not but when 'LeadContact' renders in browser it amends URL. Browser shows URL like http://name:50656/umbraco/Surface/HealthInsurance/LeadContact?leadOptionId=70 while I m expecting it should be

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

Can you please guide I can correct it ? Below is my code:

 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);
        }

Thanks for your help and sharing.


回答1:


Add the following rewrite rule to config\UrlRewriting.config:

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

Recycle IIS and you should be able to go to http://name:50656/HealthInsurance/LeadContact?leadOptionId=70 and get your desired outcome.

You could also look into Custom MVC routing in Umbraco



来源:https://stackoverflow.com/questions/27357230/redirecttoaction-is-not-working-correctly-in-surfacecontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!