[英]How to pass a URL as a query string parameter in MVC
有谁知道如何传递URL作为查询字符串参数,然后在HttpGet方法中获取URl作为参数?
非常感谢所有答案。 最后我把它分类了。 请参阅下面的我的修复:
[Route("api/[controller]")]
public class UrlController : Controller
{
[HttpGet("{*longUrl}")]
public string ShortUrl(string longUrl)
{
var test = longUrl + Request.QueryString;
return JsonConvert.SerializeObject(GetUrlToken(test));
}
像这样?
<a href="/Home/Index?url=@HttpUtility.UrlEncode("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();
}
HttpUtility.UrlEncode应该为你完成这项工作
404可能是因为应用程序未处于运行模式
托管您的应用程序并在本地尝试它应该根据需要工作
我正在尝试http:// localhost:11331 / Home /?id = http%3A%2F%2Flocalhost%3A11331%2F
即使重定向到启动屏幕,一切都工作正常
或者发布你得到的完整网址,以便我可以帮助你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.