Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a URL as a query string parameter in MVC

does anyone know how to pass a URL as a query string parameter and then get the URl in HttpGet method as a parameter ?

like image 648
Raj Avatar asked Jan 08 '23 05:01

Raj


2 Answers

Thanks so much for all the answers. Finally I got it sorted. Please refer to my fix below:

[Route("api/[controller]")]
public class UrlController : Controller
{
    [HttpGet("{*longUrl}")]
    public string ShortUrl(string longUrl)
    {
        var test = longUrl + Request.QueryString;

        return JsonConvert.SerializeObject(GetUrlToken(test));
    }
like image 129
Raj Avatar answered Jan 10 '23 17:01

Raj


just like this?

<a href="/Home/[email protected]("http://stackoverflow.com")">current url with UrlEncode</a>

[HttpGet]
public ActionResult Index(string url = null)
{
    ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
    return View();
}
like image 23
Sky Fang Avatar answered Jan 10 '23 19:01

Sky Fang