Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

Getting a HARD URL for Your own Action

$
0
0
Does anyone know how to create a simple hard URL to an action in MVC5? I'm not using it in the context of a View though, I am generating a unique URL and storing it into the database... Trying to use this:

public IHttpActionResult Create(Url url) 
{ 
UrlHelper helper = new UrlHelper(); 
if (!ModelState.IsValid) 
{ 
BadRequest(); 
} 
url.OurUrl = helper.Action("Go","Redirect", null, "http") + url.UrlId; 
_context.Urls.Add(url); 
_context.SaveChanges(); 
 

return Created(new Uri(Request.RequestUri + "/" + url.UrlId), Url); 
} 


I've tried all kinds of variations on the Action() method... Like just using Go and Redirect as arguments... And what you see there. But it keeps telling me that routeCollection cannot be null
I'm confused because routeCollection isn't even a parameter listed in the method. Thanks.

Viewing all articles
Browse latest Browse all 3938

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>