How to know the View() call link. NET MVC

Asked

Viewed 120 times

2

I have a controller with a view at the end to show details of a company. I am making a code that allows generating a url to the company details through the goo.Gl to be easier and enjoyable to share, and I need to put as input the link to the view. This link is stored in the database, associated with my model. See:

public ActionResult scoreDetails(int id)
{        
    res = PresentationServices.Helper.GetCompanyDetails(id);                
    //ShortLink 
    ViewBag.shortLink = 
    PresentationServices.Helper.GetCompanyShortLink(id, "LINK PARA A VIEW" );
    return View(res);
}
  • Why cast of int in a variable that is int (int)id????

  • for nothing kkk, thanks for the repair I already took out of my code.

1 answer

2


The simplest way to achieve this is through Request.RequestUri.PathAndQuery:

ViewBag.shortLink = 
    PresentationServices.Helper.GetCompanyShortLink((int)id, Request.RequestUri.PathAndQuery);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.