i want to make some question about asp.net mvc. How i call asp.net mvc controller action from normal aspx web form? Our project is used asp.net mvc framework with visual studio 2008 C#.net. For eg,i want to use like this in normal aspx web form.
public ActionResult callMvc()
{
return RedirectToAction("Display","TempController");
}
I know it should not using li开发者_JS百科ke this way in MVC project,but,we need for some case.
Regards
Indi
You can just use a Response.Redirect with the right url which get routed to your controller in question, I guess in your case, that is:
Response.Redirect("/Temp/Display");
It would be a better idea to use the Url helper to resolve the url for you, that way if your routes change then you don't have to refactor your code. Use this method;
Response.Redirect(Url.Action("Display", "Temp"));
I have never used it in this context before but I believe it should work as expected.
Use following code:
Response.Redirect("~/Home/Index");
Controller/action
In WebForm cs file (class derived from System.Web.UI.Page) use:
this.Response.RedirectToRoute(new { controller="ControllerToRedirectTo", action="ActionToRedirectTo", id=5, SomeOtherActionParameter="Parameter value" });
精彩评论