Get URL for action from controller

I call the controller action from the view, inside this controller I need to call another action, which I will call to save the view in a network location as HTML or image.

How to get the Action URL from inside the controller. Please note that I need the actual URL, this means that RedirectionToAction or View () are not working.

Why? I need to pass the url that will contain the view call. This view will be used to create an image or HTML document using System.Windows.Forms.WebBrowser.

.NET 3.5 WITH#; MVC 1;

I could do something like that, but its dirty ... well, that leaves me with that dirty feeling.

using(Html.BeginForm("Action", "MyWorkflowController", 
new {
   MyId = "bla",
   URLToGenerateImage = Url.Action("GenerateImage", "MyWorkflowController")   
}))
+3
source share
2 answers

I ended up using MvcContrib.UI.BlockRenderer to convert to View in Html instead of generating an image. I continued to save the html string in the file system location.

Here is the link for more information.

http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/

+1
source

How about a ContentResult - represents a text result, so you may have

/ controller / GetURL / identifier

Public ActionResult GetUrl(int id)
{  
   // builds url to view (Controller/Image/id || Controller/Html/id)
   var url = BuildImageUrl(id);
   return ContentResult(url);
}

in which you could:

<a href="<% Html.RenderAction("GetUrl", "Controller", new { id = idSource } ); %>">GenerateImage</a>
0
source

Source: https://habr.com/ru/post/1781218/


All Articles