问题
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