0

I am trying to create an MVC link via Url.Action inside my Web API Controller

string scheme = Request.RequestUri.Scheme;
System.Web.Mvc.UrlHelper helper = new System.Web.Mvc.UrlHelper();
string linkBackUrl = helper.Action("TestAction", "TestController", new{ code=code1, code2 = code2}, scheme);

And I am getting the error (when debugging) on the line linkBackUrl:

attempted to read or write protected memory. this is often an indication that other memory is corrupt.

Is there another way to create the linkBackUrl inside the Web API controller?

2
  • If you are trying to get a reference of the current HttpContext try this: System.Web.Mvc.UrlHelper helper = new System.Web.Mvc.UrlHelper(HttpContext.Current.Request.RequestContext); Commented Mar 9, 2015 at 14:50
  • No need to build your own UrlHelper in an ApiController--it comes with one Commented Mar 9, 2015 at 15:01

1 Answer 1

1

I think this is what your looking for :

         string linkBackUrl = Url.Action("TestAction", "TestController", new { code = code1, code2 = code2 });

Or on your view:

<button onclick="window.history.back();">Go Back</button>
Sign up to request clarification or add additional context in comments.

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.