2

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 like this way in MVC project,but,we need for some case.

Regards

Indi

4 Answers 4

4

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");
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your answer my fri,Before i call that action,url is like this "localhost:50834/Normal/WebForm.aspx" it's in normal aspx web form,And then,i call action like yours way. it shows error "The resource cannot be found".url becomes like this "localhost:50834/Normal/Temp/Display" Actually,this controller url is "localhost:50834/Temp/Display" How i solve? regards Indi
@Indi: try Response.Redirect("../Temp/Display");
1

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.

Comments

0

Use following code:

Response.Redirect("~/Home/Index");

Controller/action

1 Comment

Can you expand on your answer?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.