Batuta
Batuta

Reputation: 1714

Creating an MVC Link through Url.Action Inside a Web API Controller

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?

Upvotes: 0

Views: 611

Answers (1)

Lucas L Roselli
Lucas L Roselli

Reputation: 2830

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>

Upvotes: 1

Related Questions